Switch to SMAppService

This commit is contained in:
Max Goedjen 2025-01-04 01:10:57 -08:00
parent c2563be404
commit 28a4dafad4
No known key found for this signature in database

View File

@ -26,7 +26,7 @@ struct LaunchAgentController {
let config = NSWorkspace.OpenConfiguration()
config.activates = false
do {
let app = try await NSWorkspace.shared.openApplication(at: url, configuration: config)
try await NSWorkspace.shared.openApplication(at: url, configuration: config)
logger.debug("Agent force launched")
return true
} catch {
@ -36,8 +36,17 @@ struct LaunchAgentController {
}
private func setEnabled(_ enabled: Bool) -> Bool {
// FIXME: THIS
SMLoginItemSetEnabled(Bundle.main.agentBundleID as CFString, enabled)
let service = SMAppService.loginItem(identifier: Bundle.main.agentBundleID)
do {
if enabled {
try service.register()
} else {
try service.unregister()
}
return true
} catch {
return false
}
}
}