Allows auto-launch for every user's build

This commit is contained in:
Alex Lavallee 2020-11-30 18:25:52 -08:00
parent 9c4b4ac39e
commit 670bfb17d5
No known key found for this signature in database
GPG Key ID: FF636FB2C9E94B03
2 changed files with 5 additions and 4 deletions

View File

@ -9,7 +9,7 @@ protocol AgentStatusCheckerProtocol: ObservableObject {
class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
@Published var running: Bool = false @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() { init() {
check() check()
@ -21,7 +21,7 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
// All processes, including ones from older versions, etc // All processes, including ones from older versions, etc
var secretAgentProcesses: [NSRunningApplication] { var secretAgentProcesses: [NSRunningApplication] {
NSRunningApplication.runningApplications(withBundleIdentifier: bundleID ?? "com.maxgoedjen.Secretive.SecretAgent") NSRunningApplication.runningApplications(withBundleIdentifier: bundleID )
} }
// The process corresponding to this instance of Secretive // The process corresponding to this instance of Secretive

View File

@ -4,7 +4,8 @@ import AppKit
import OSLog import OSLog
struct LaunchAgentController { struct LaunchAgentController {
let bundleID = Bundle.main.bundleIdentifier!.replacingOccurrences(of: "Host", with: "SecretAgent")
func install(completion: (() -> Void)? = nil) { func install(completion: (() -> Void)? = nil) {
Logger().debug("Installing agent") Logger().debug("Installing agent")
_ = setEnabled(false) _ = setEnabled(false)
@ -32,7 +33,7 @@ struct LaunchAgentController {
} }
private func setEnabled(_ enabled: Bool) -> Bool { private func setEnabled(_ enabled: Bool) -> Bool {
SMLoginItemSetEnabled("com.maxgoedjen.Secretive.SecretAgent" as CFString, enabled) SMLoginItemSetEnabled(bundleID as CFString, enabled)
} }
} }