Repo // Don't check update if serving `com.apple.SecurityAgent`.
This commit is contained in:
parent
95b8f3fd4c
commit
f1cfe67c97
|
@ -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() {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue