diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift index d38579bf..df14fc23 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift @@ -17,6 +17,7 @@ import UpdateSputnik @objc(AppDelegate) public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate { public static let shared = AppDelegate() + private var folderMonitor = FolderMonitor( url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false)) ) @@ -29,9 +30,9 @@ public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCen return .init(string: urlText) } - public func checkUpdate(forced: Bool) { + public func checkUpdate(forced: Bool, shouldBypass: @escaping () -> Bool) { guard let url = Self.updateInfoSourceURL else { return } - UpdateSputnik.shared.checkForUpdate(forced: forced, url: url) + UpdateSputnik.shared.checkForUpdate(forced: forced, url: url) { shouldBypass() } } } @@ -89,11 +90,6 @@ public extension AppDelegate { self.reloadOnFolderChangeHappens() } if LMMgr.userDataFolderExists { folderMonitor.startMonitoring() } - - // 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。 - if PrefMgr.shared.checkUpdateAutomatically { - checkUpdate(forced: false) - } } func updateDirectoryMonitorPath() { diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Core.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Core.swift index 42c54c55..16510860 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Core.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Core.swift @@ -15,7 +15,6 @@ import PopupCompositionBuffer import Shared import ShiftKeyUpChecker import TooltipUI -import UpdateSputnik /// 輸入法控制模組,乃在輸入法端用以控制輸入行為的基礎型別。 /// @@ -289,6 +288,12 @@ public extension SessionCtl { vCLog("activateServer(\(senderBundleID))") self.isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID self.clientBundleIdentifier = senderBundleID + // 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。 + if PrefMgr.shared.checkUpdateAutomatically { + AppDelegate.shared.checkUpdate(forced: false) { + senderBundleID == "com.apple.SecurityAgent" + } + } } } DispatchQueue.main.async { @@ -338,7 +343,6 @@ public extension SessionCtl { } DispatchQueue.main.async { - AppDelegate.shared.checkUpdate(forced: false) AppDelegate.shared.checkMemoryUsage() } diff --git a/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift b/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift index 76c78e17..baf9a837 100644 --- a/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift +++ b/Packages/vChewing_UpdateSputnik/Sources/UpdateSputnik/UpdateSputnik.swift @@ -19,8 +19,10 @@ public class UpdateSputnik { public init() {} - public func checkForUpdate(forced: Bool = false, url: URL) { - guard !busy else { return } + public func checkForUpdate(forced: Bool = false, url: URL, shouldBypass: @escaping () -> Bool) { + let shouldBypass = shouldBypass() + silentMode = shouldBypass + guard !shouldBypass, !busy else { return } if !forced { if !UserDefaults.standard.bool(forKey: kCheckUpdateAutomatically) { return } @@ -36,7 +38,9 @@ public class UpdateSputnik { let task = URLSession.shared.dataTask(with: request) { data, _, error in if let error = error { DispatchQueue.main.async { - self.showError(message: error.localizedDescription) + if !self.silentMode { + self.showError(message: error.localizedDescription) + } self.currentTask = nil } return @@ -49,6 +53,7 @@ public class UpdateSputnik { // MARK: - Private Properties + private var silentMode = false private var isCurrentCheckForced = false var sessionConfiguration = URLSessionConfiguration.background(withIdentifier: Bundle.main.bundleIdentifier!) @@ -58,7 +63,9 @@ public class UpdateSputnik { didSet { if let data = data { DispatchQueue.main.async { - self.dataDidSet(data: data) + if !self.silentMode { + self.dataDidSet(data: data) + } self.currentTask = nil } } diff --git a/Source/Modules/SessionCtl_Menu.swift b/Source/Modules/SessionCtl_Menu.swift index 55cec480..8e57a605 100644 --- a/Source/Modules/SessionCtl_Menu.swift +++ b/Source/Modules/SessionCtl_Menu.swift @@ -372,7 +372,9 @@ public extension SessionCtl { } @objc func checkForUpdate(_: Any? = nil) { - AppDelegate.shared.checkUpdate(forced: true) + AppDelegate.shared.checkUpdate(forced: true) { [weak self] in + self?.clientBundleIdentifier == "com.apple.SecurityAgent" + } } @objc func openUserDataFolder(_: Any? = nil) {