diff --git a/Source/Modules/AppDelegate.swift b/Source/Modules/AppDelegate.swift index bda7d169..e0e96849 100644 --- a/Source/Modules/AppDelegate.swift +++ b/Source/Modules/AppDelegate.swift @@ -20,6 +20,19 @@ public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCen private var folderMonitor = FolderMonitor( url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false)) ) + + public static var updateInfoSourceURL: URL? { + guard let urlText = Bundle.main.infoDictionary?["UpdateInfoEndpoint"] as? String else { + NSLog("vChewingDebug: Fatal error: Info.plist wrecked. It needs to have correct 'UpdateInfoEndpoint' value.") + return nil + } + return .init(string: urlText) + } + + public func checkUpdate(forced: Bool) { + guard let url = Self.updateInfoSourceURL else { return } + UpdateSputnik.shared.checkForUpdate(forced: forced, url: url) + } } // MARK: - Private Functions @@ -80,7 +93,7 @@ public extension AppDelegate { // 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。 if PrefMgr.shared.checkUpdateAutomatically { - UpdateSputnik.shared.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) + checkUpdate(forced: false) } } diff --git a/Source/Modules/SessionCtl_Core.swift b/Source/Modules/SessionCtl_Core.swift index 4532137c..81f82546 100644 --- a/Source/Modules/SessionCtl_Core.swift +++ b/Source/Modules/SessionCtl_Core.swift @@ -318,7 +318,7 @@ public extension SessionCtl { } DispatchQueue.main.async { - UpdateSputnik.shared.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) + AppDelegate.shared.checkUpdate(forced: false) AppDelegate.shared.checkMemoryUsage() } diff --git a/Source/Modules/SessionCtl_Menu.swift b/Source/Modules/SessionCtl_Menu.swift index 4935a819..ef42c31d 100644 --- a/Source/Modules/SessionCtl_Menu.swift +++ b/Source/Modules/SessionCtl_Menu.swift @@ -373,7 +373,7 @@ public extension SessionCtl { } @objc func checkForUpdate(_: Any? = nil) { - UpdateSputnik.shared.checkForUpdate(forced: true, url: kUpdateInfoSourceURL) + AppDelegate.shared.checkUpdate(forced: true) } @objc func openUserDataFolder(_: Any? = nil) { diff --git a/Source/Modules/main.swift b/Source/Modules/main.swift index 3d8f446c..57cd7b60 100644 --- a/Source/Modules/main.swift +++ b/Source/Modules/main.swift @@ -57,16 +57,7 @@ else { exit(-1) } -guard let mainBundleInfoDict = Bundle.main.infoDictionary, - let strUpdateInfoSource = mainBundleInfoDict["UpdateInfoEndpoint"] as? String, - let urlUpdateInfoSource = URL(string: strUpdateInfoSource) -else { - NSLog("vChewingDebug: Fatal error: Info.plist wrecked. It needs to have correct 'UpdateInfoEndpoint' value.") - exit(-1) -} - public let theServer = server -public let kUpdateInfoSourceURL = urlUpdateInfoSource NSApplication.shared.delegate = AppDelegate.shared _ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)