From 70f47407f97626c48d956f998989a2340738aed0 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 12 Oct 2022 14:11:12 +0800 Subject: [PATCH] UpdateSputnik // Use shared instance; Fix wrong key name. --- .../Sources/UpdateSputnik/UpdateSputnik.swift | 3 ++- Source/Modules/AppDelegate.swift | 10 +--------- Source/Modules/SessionCtl_Core.swift | 3 ++- Source/Modules/SessionCtl_Menu.swift | 3 ++- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift b/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift index 4d4a47b9..936f5ebf 100644 --- a/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift +++ b/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift @@ -9,11 +9,12 @@ import Cocoa public class UpdateSputnik { + public static var shared: UpdateSputnik = .init() public var varkUpdateInfoPageURLKey: String = "UpdateInfoSite" public var varkUpdateCheckDateKeyPrevious: String = "PreviousUpdateCheckDate" public var varkUpdateCheckDateKeyNext: String = "NextUpdateCheckDate" public var varkUpdateCheckInterval: TimeInterval = 114_514 - public var varCheckUpdateAutomatically = "ChecvarkUpdateAutomatically" + public var varCheckUpdateAutomatically = "CheckUpdateAutomatically" public init() {} diff --git a/Source/Modules/AppDelegate.swift b/Source/Modules/AppDelegate.swift index f86e8036..d829b6b6 100644 --- a/Source/Modules/AppDelegate.swift +++ b/Source/Modules/AppDelegate.swift @@ -21,7 +21,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele } } - public let updateSputnik = UpdateSputnik() public var folderMonitor = FolderMonitor( url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false)) ) @@ -56,16 +55,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele PrefMgr.shared.fixOddPreferences() - // 配置更新小助手 - updateSputnik.varkUpdateInfoPageURLKey = "UpdateInfoSite" - updateSputnik.varkUpdateCheckDateKeyPrevious = "PreviousUpdateCheckDate" - updateSputnik.varkUpdateCheckDateKeyNext = "NextUpdateCheckDate" - updateSputnik.varkUpdateCheckInterval = 114_514 - updateSputnik.varCheckUpdateAutomatically = "ChecvarkUpdateAutomatically" - // 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。 if PrefMgr.shared.checkUpdateAutomatically { - updateSputnik.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) + UpdateSputnik.shared.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) } } diff --git a/Source/Modules/SessionCtl_Core.swift b/Source/Modules/SessionCtl_Core.swift index 845f03e0..e31fcfc4 100644 --- a/Source/Modules/SessionCtl_Core.swift +++ b/Source/Modules/SessionCtl_Core.swift @@ -13,6 +13,7 @@ import PopupCompositionBuffer import Shared import ShiftKeyUpChecker import TooltipUI +import UpdateSputnik /// 輸入法控制模組,乃在輸入法端用以控制輸入行為的基礎型別。 /// @@ -202,7 +203,7 @@ extension SessionCtl { } DispatchQueue.main.async { - (NSApp.delegate as? AppDelegate)?.updateSputnik.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) + UpdateSputnik.shared.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) } handle(state: IMEState.ofEmpty()) diff --git a/Source/Modules/SessionCtl_Menu.swift b/Source/Modules/SessionCtl_Menu.swift index 42cc7b3f..8237f9e1 100644 --- a/Source/Modules/SessionCtl_Menu.swift +++ b/Source/Modules/SessionCtl_Menu.swift @@ -8,6 +8,7 @@ import NotifierUI import Preferences +import UpdateSputnik extension Bool { fileprivate var state: NSControl.StateValue { @@ -316,7 +317,7 @@ extension SessionCtl { } @objc public func checkForUpdate(_: Any?) { - (NSApp.delegate as? AppDelegate)?.updateSputnik.checkForUpdate(forced: true, url: kUpdateInfoSourceURL) + UpdateSputnik.shared.checkForUpdate(forced: true, url: kUpdateInfoSourceURL) } @objc public func openUserDataFolder(_: Any?) {