From fd9aa80ca8487180084be321d1febed90e0d9867 Mon Sep 17 00:00:00 2001 From: Alex Lavallee <73203142+lavalleeale@users.noreply.github.com> Date: Mon, 30 Nov 2020 18:25:52 -0800 Subject: [PATCH] Allows auto-launch for every user's build --- Secretive/Controllers/AgentStatusChecker.swift | 4 ++-- Secretive/Controllers/LaunchAgentController.swift | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Secretive/Controllers/AgentStatusChecker.swift b/Secretive/Controllers/AgentStatusChecker.swift index ab33384..04b7c0a 100644 --- a/Secretive/Controllers/AgentStatusChecker.swift +++ b/Secretive/Controllers/AgentStatusChecker.swift @@ -9,7 +9,7 @@ protocol AgentStatusCheckerProtocol: ObservableObject { class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { @Published var running: Bool = false - let bundleID = Bundle.main.bundleIdentifier?.replacingOccurrences(of: "Host", with: "SecretAgent") + let bundleID = Bundle.main.bundleIdentifier!.replacingOccurrences(of: "Host", with: "SecretAgent") init() { check() @@ -21,7 +21,7 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { // All processes, including ones from older versions, etc var secretAgentProcesses: [NSRunningApplication] { - NSRunningApplication.runningApplications(withBundleIdentifier: bundleID ?? "com.maxgoedjen.Secretive.SecretAgent") + NSRunningApplication.runningApplications(withBundleIdentifier: bundleID ) } // The process corresponding to this instance of Secretive diff --git a/Secretive/Controllers/LaunchAgentController.swift b/Secretive/Controllers/LaunchAgentController.swift index 97915f8..6d9cf23 100644 --- a/Secretive/Controllers/LaunchAgentController.swift +++ b/Secretive/Controllers/LaunchAgentController.swift @@ -4,7 +4,8 @@ import AppKit import OSLog struct LaunchAgentController { - + + let bundleID = Bundle.main.bundleIdentifier!.replacingOccurrences(of: "Host", with: "SecretAgent") func install(completion: (() -> Void)? = nil) { Logger().debug("Installing agent") _ = setEnabled(false) @@ -32,7 +33,7 @@ struct LaunchAgentController { } private func setEnabled(_ enabled: Bool) -> Bool { - SMLoginItemSetEnabled("com.maxgoedjen.Secretive.SecretAgent" as CFString, enabled) + SMLoginItemSetEnabled(bundleID as CFString, enabled) } }