From 28a4dafad4449fc1f212a3677178cb36111a9519 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sat, 4 Jan 2025 01:10:57 -0800 Subject: [PATCH] Switch to SMAppService --- .../Controllers/LaunchAgentController.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/Secretive/Controllers/LaunchAgentController.swift b/Sources/Secretive/Controllers/LaunchAgentController.swift index 2cf72e2..a65f8b0 100644 --- a/Sources/Secretive/Controllers/LaunchAgentController.swift +++ b/Sources/Secretive/Controllers/LaunchAgentController.swift @@ -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 + } } }