diff --git a/Kit/helpers.swift b/Kit/helpers.swift index df8e68f3..b0967533 100644 --- a/Kit/helpers.swift +++ b/Kit/helpers.swift @@ -1067,18 +1067,23 @@ public class SMCHelper { return self.connection != nil } - private func helperStatus(completion: @escaping (_ installed: Bool) -> Void) { + public func checkForUpdate() { let helperURL = Bundle.main.bundleURL.appendingPathComponent("Contents/Library/LaunchServices/eu.exelban.Stats.SMC.Helper") - guard - let helperBundleInfo = CFBundleCopyInfoDictionaryForURL(helperURL as CFURL) as? [String: Any], - let helperVersion = helperBundleInfo["CFBundleShortVersionString"] as? String, - let helper = self.helper(completion) else { - completion(false) - return - } + guard let helperBundleInfo = CFBundleCopyInfoDictionaryForURL(helperURL as CFURL) as? [String: Any], + let helperVersion = helperBundleInfo["CFBundleShortVersionString"] as? String, + let helper = self.helper(nil) else { return } helper.version { installedHelperVersion in - completion(installedHelperVersion == helperVersion) + guard installedHelperVersion != helperVersion else { return } + print("new version of SMC helper is detected, going to update...") + self.uninstall(silent: true) + self.install { installed in + if installed { + print("the new version of SMC helper was successfully installed") + } else { + print("error when installing a new version of the SMC helper") + } + } } } @@ -1158,7 +1163,7 @@ public class SMCHelper { return helper } - public func uninstall() { + public func uninstall(silent: Bool = false) { if let count = SMC.shared.getValue("FNum") { for i in 0..CFBundleName eu.exelban.Stats.SMC.Helper CFBundleShortVersionString - 1.0 + 1.0.0 CFBundleVersion 1 SMAuthorizedClients - anchor apple generic and identifier "eu.exelban.Stats" and (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = RP2S87B72W) + anchor apple generic and identifier "eu.exelban.Stats" and (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = RP2S87B72W) diff --git a/Stats/AppDelegate.swift b/Stats/AppDelegate.swift index 884b590b..93d212f8 100755 --- a/Stats/AppDelegate.swift +++ b/Stats/AppDelegate.swift @@ -58,6 +58,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele self.parseArguments() self.parseVersion() + SMCHelper.shared.checkForUpdate() self.setup { modules.forEach{ $0.mount() } self.settingsWindow.setModules()