mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added an SMC helper update process on the start
This commit is contained in:
@@ -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..<Int(count) {
|
||||
self.setFanMode(i, mode: 0)
|
||||
@@ -1166,7 +1171,9 @@ public class SMCHelper {
|
||||
}
|
||||
guard let helper = self.helper(nil) else { return }
|
||||
helper.uninstall()
|
||||
NotificationCenter.default.post(name: .fanHelperState, object: nil, userInfo: ["state": false])
|
||||
if !silent {
|
||||
NotificationCenter.default.post(name: .fanHelperState, object: nil, userInfo: ["state": false])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
<key>CFBundleName</key>
|
||||
<string>eu.exelban.Stats.SMC.Helper</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>SMAuthorizedClients</key>
|
||||
<array>
|
||||
<string>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)</string>
|
||||
<string>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)</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user