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)
|
@objc(AppDelegate)
|
||||||
public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
|
public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
|
||||||
public static let shared = AppDelegate()
|
public static let shared = AppDelegate()
|
||||||
|
|
||||||
private var folderMonitor = FolderMonitor(
|
private var folderMonitor = FolderMonitor(
|
||||||
url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false))
|
url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false))
|
||||||
)
|
)
|
||||||
|
@ -29,9 +30,9 @@ public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCen
|
||||||
return .init(string: urlText)
|
return .init(string: urlText)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func checkUpdate(forced: Bool) {
|
public func checkUpdate(forced: Bool, shouldBypass: @escaping () -> Bool) {
|
||||||
guard let url = Self.updateInfoSourceURL else { return }
|
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()
|
self.reloadOnFolderChangeHappens()
|
||||||
}
|
}
|
||||||
if LMMgr.userDataFolderExists { folderMonitor.startMonitoring() }
|
if LMMgr.userDataFolderExists { folderMonitor.startMonitoring() }
|
||||||
|
|
||||||
// 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。
|
|
||||||
if PrefMgr.shared.checkUpdateAutomatically {
|
|
||||||
checkUpdate(forced: false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateDirectoryMonitorPath() {
|
func updateDirectoryMonitorPath() {
|
||||||
|
|
|
@ -15,7 +15,6 @@ import PopupCompositionBuffer
|
||||||
import Shared
|
import Shared
|
||||||
import ShiftKeyUpChecker
|
import ShiftKeyUpChecker
|
||||||
import TooltipUI
|
import TooltipUI
|
||||||
import UpdateSputnik
|
|
||||||
|
|
||||||
/// 輸入法控制模組,乃在輸入法端用以控制輸入行為的基礎型別。
|
/// 輸入法控制模組,乃在輸入法端用以控制輸入行為的基礎型別。
|
||||||
///
|
///
|
||||||
|
@ -289,6 +288,12 @@ public extension SessionCtl {
|
||||||
vCLog("activateServer(\(senderBundleID))")
|
vCLog("activateServer(\(senderBundleID))")
|
||||||
self.isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
|
self.isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
|
||||||
self.clientBundleIdentifier = senderBundleID
|
self.clientBundleIdentifier = senderBundleID
|
||||||
|
// 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。
|
||||||
|
if PrefMgr.shared.checkUpdateAutomatically {
|
||||||
|
AppDelegate.shared.checkUpdate(forced: false) {
|
||||||
|
senderBundleID == "com.apple.SecurityAgent"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -338,7 +343,6 @@ public extension SessionCtl {
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
AppDelegate.shared.checkUpdate(forced: false)
|
|
||||||
AppDelegate.shared.checkMemoryUsage()
|
AppDelegate.shared.checkMemoryUsage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,10 @@ public class UpdateSputnik {
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
public func checkForUpdate(forced: Bool = false, url: URL) {
|
public func checkForUpdate(forced: Bool = false, url: URL, shouldBypass: @escaping () -> Bool) {
|
||||||
guard !busy else { return }
|
let shouldBypass = shouldBypass()
|
||||||
|
silentMode = shouldBypass
|
||||||
|
guard !shouldBypass, !busy else { return }
|
||||||
|
|
||||||
if !forced {
|
if !forced {
|
||||||
if !UserDefaults.standard.bool(forKey: kCheckUpdateAutomatically) { return }
|
if !UserDefaults.standard.bool(forKey: kCheckUpdateAutomatically) { return }
|
||||||
|
@ -36,7 +38,9 @@ public class UpdateSputnik {
|
||||||
let task = URLSession.shared.dataTask(with: request) { data, _, error in
|
let task = URLSession.shared.dataTask(with: request) { data, _, error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
if !self.silentMode {
|
||||||
self.showError(message: error.localizedDescription)
|
self.showError(message: error.localizedDescription)
|
||||||
|
}
|
||||||
self.currentTask = nil
|
self.currentTask = nil
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -49,6 +53,7 @@ public class UpdateSputnik {
|
||||||
|
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
|
|
||||||
|
private var silentMode = false
|
||||||
private var isCurrentCheckForced = false
|
private var isCurrentCheckForced = false
|
||||||
var sessionConfiguration = URLSessionConfiguration.background(withIdentifier: Bundle.main.bundleIdentifier!)
|
var sessionConfiguration = URLSessionConfiguration.background(withIdentifier: Bundle.main.bundleIdentifier!)
|
||||||
|
|
||||||
|
@ -58,7 +63,9 @@ public class UpdateSputnik {
|
||||||
didSet {
|
didSet {
|
||||||
if let data = data {
|
if let data = data {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
if !self.silentMode {
|
||||||
self.dataDidSet(data: data)
|
self.dataDidSet(data: data)
|
||||||
|
}
|
||||||
self.currentTask = nil
|
self.currentTask = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,7 +372,9 @@ public extension SessionCtl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func checkForUpdate(_: Any? = nil) {
|
@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) {
|
@objc func openUserDataFolder(_: Any? = nil) {
|
||||||
|
|
Loading…
Reference in New Issue