AppDelegate // Manage Update Info URL internally.

This commit is contained in:
ShikiSuen 2023-08-22 11:43:40 +08:00
parent 0142258f34
commit a56b55125a
4 changed files with 16 additions and 12 deletions

View File

@ -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)
}
}

View File

@ -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()
}

View File

@ -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) {

View File

@ -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)