Repo // Don't check update if serving `com.apple.SecurityAgent`.

This commit is contained in:
ShikiSuen 2023-09-21 18:45:59 +08:00
parent 95b8f3fd4c
commit f1cfe67c97
4 changed files with 23 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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