From edeb603ce0d73a5f599b05f96a94774a59f663d1 Mon Sep 17 00:00:00 2001 From: Alex Lavallee <73203142+lavalleeale@users.noreply.github.com> Date: Sun, 27 Dec 2020 17:07:56 -0800 Subject: [PATCH] made a Bundle extension in SecretKit with hostBundleID and agentBundleID properties --- SecretKit/Common/bundleIDs.swift | 15 +++++++++++++++ Secretive/Controllers/AgentStatusChecker.swift | 4 ++-- Secretive/Controllers/LaunchAgentController.swift | 4 ++-- .../ShellConfigurationController.swift | 3 ++- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 SecretKit/Common/bundleIDs.swift diff --git a/SecretKit/Common/bundleIDs.swift b/SecretKit/Common/bundleIDs.swift new file mode 100644 index 0000000..bb651c8 --- /dev/null +++ b/SecretKit/Common/bundleIDs.swift @@ -0,0 +1,15 @@ +// +// bundleIDs.swift +// SecretKit +// +// Created by Alex lavallee on 12/27/20. +// Copyright © 2020 Max Goedjen. All rights reserved. +// + +import Foundation + + +extension Bundle { + public var agentBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "Host", with: "SecretAgent"))!} + public var hostBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "SecretAgent", with: "Host"))!} +} diff --git a/Secretive/Controllers/AgentStatusChecker.swift b/Secretive/Controllers/AgentStatusChecker.swift index 04b7c0a..c8c0465 100644 --- a/Secretive/Controllers/AgentStatusChecker.swift +++ b/Secretive/Controllers/AgentStatusChecker.swift @@ -1,6 +1,7 @@ import Foundation import Combine import AppKit +import SecretKit protocol AgentStatusCheckerProtocol: ObservableObject { var running: Bool { get } @@ -9,7 +10,6 @@ protocol AgentStatusCheckerProtocol: ObservableObject { class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { @Published var running: Bool = false - 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 ) + NSRunningApplication.runningApplications(withBundleIdentifier: Bundle.main.agentBundleID) } // The process corresponding to this instance of Secretive diff --git a/Secretive/Controllers/LaunchAgentController.swift b/Secretive/Controllers/LaunchAgentController.swift index 6d9cf23..1f3ef5d 100644 --- a/Secretive/Controllers/LaunchAgentController.swift +++ b/Secretive/Controllers/LaunchAgentController.swift @@ -2,10 +2,10 @@ import Foundation import ServiceManagement import AppKit import OSLog +import SecretKit struct LaunchAgentController { - let bundleID = Bundle.main.bundleIdentifier!.replacingOccurrences(of: "Host", with: "SecretAgent") func install(completion: (() -> Void)? = nil) { Logger().debug("Installing agent") _ = setEnabled(false) @@ -33,7 +33,7 @@ struct LaunchAgentController { } private func setEnabled(_ enabled: Bool) -> Bool { - SMLoginItemSetEnabled(bundleID as CFString, enabled) + SMLoginItemSetEnabled(Bundle.main.agentBundleID as CFString, enabled) } } diff --git a/Secretive/Controllers/ShellConfigurationController.swift b/Secretive/Controllers/ShellConfigurationController.swift index be1f42a..a7f2096 100644 --- a/Secretive/Controllers/ShellConfigurationController.swift +++ b/Secretive/Controllers/ShellConfigurationController.swift @@ -1,9 +1,10 @@ import Foundation import Cocoa +import SecretKit struct ShellConfigurationController { - let socketPath = (NSHomeDirectory().replacingOccurrences(of: "Secretive.Host", with: "Secretive.SecretAgent") as NSString).appendingPathComponent("socket.ssh") as String + let socketPath = (NSHomeDirectory().replacingOccurrences(of: Bundle.main.hostBundleID, with: Bundle.main.agentBundleID) as NSString).appendingPathComponent("socket.ssh") as String var shellInstructions: [ShellConfigInstruction] { [