Fix XPC validation

This commit is contained in:
世界
2026-01-05 15:42:56 +08:00
parent af9cfd0f59
commit 8a62a58ce7
12 changed files with 278 additions and 145 deletions
@@ -1,7 +1,10 @@
#if os(macOS)
import Foundation
import os
import ServiceManagement
private let logger = Logger(category: "HelperServiceManager")
public enum HelperServiceManager {
private static var rootHelperService: SMAppService {
SMAppService.daemon(plistName: "\(AppConfiguration.rootHelperBundleID).plist")
@@ -21,5 +24,25 @@
public static func unregisterRootHelper() throws {
try rootHelperService.unregister()
}
public static func updateRootHelperIfNeeded() async {
guard rootHelperStatus == .enabled else { return }
do {
let installedVersion = try RootHelperClient.shared.getVersion()
let currentVersion = Bundle.main.version
guard currentVersion != installedVersion else { return }
} catch {
logger.warning("Failed to get root helper version, updating: \(error.localizedDescription)")
}
do {
try unregisterRootHelper()
try await Task.sleep(for: .seconds(1))
try registerRootHelper()
} catch {
logger.error("Failed to update root helper: \(error.localizedDescription)")
}
}
}
#endif