diff --git a/SecretKit/Common/BundleIDs.swift b/SecretKit/Common/BundleIDs.swift new file mode 100644 index 0000000..de4967d --- /dev/null +++ b/SecretKit/Common/BundleIDs.swift @@ -0,0 +1,7 @@ +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.xcodeproj/project.pbxproj b/Secretive.xcodeproj/project.pbxproj index b07e940..70a3fbf 100644 --- a/Secretive.xcodeproj/project.pbxproj +++ b/Secretive.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 50BB046B2418AAAE00D6E079 /* EmptyStoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */; }; 50C385A3240789E600AF2719 /* OpenSSHReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C385A2240789E600AF2719 /* OpenSSHReader.swift */; }; 50C385A52407A76D00AF2719 /* SecretDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C385A42407A76D00AF2719 /* SecretDetailView.swift */; }; + FA0B34672599619E0013AB3A /* BundleIDs.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0B34662599619E0013AB3A /* BundleIDs.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -308,6 +309,7 @@ 50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStoreView.swift; sourceTree = ""; }; 50C385A2240789E600AF2719 /* OpenSSHReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OpenSSHReader.swift; path = SecretKit/Common/OpenSSH/OpenSSHReader.swift; sourceTree = SOURCE_ROOT; }; 50C385A42407A76D00AF2719 /* SecretDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretDetailView.swift; sourceTree = ""; }; + FA0B34662599619E0013AB3A /* BundleIDs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleIDs.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -591,6 +593,7 @@ 5068389F2415EA4F00F55094 /* Erasers */, 506838A42415EA6800F55094 /* OpenSSH */, 5068389D241471CD00F55094 /* SecretStoreList.swift */, + FA0B34662599619E0013AB3A /* BundleIDs.swift */, ); path = Common; sourceTree = ""; @@ -1037,6 +1040,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + FA0B34672599619E0013AB3A /* BundleIDs.swift in Sources */, 501B7AE1251C56F700776EC7 /* SigningRequestProvenance.swift in Sources */, 50617DC723FCE4EA0099B055 /* SecretStore.swift in Sources */, 5099A02723FE34FA0062B6F2 /* SmartCard.swift in Sources */, diff --git a/Secretive/Controllers/AgentStatusChecker.swift b/Secretive/Controllers/AgentStatusChecker.swift index d09cd32..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 } @@ -20,7 +21,7 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { // All processes, including ones from older versions, etc var secretAgentProcesses: [NSRunningApplication] { - NSRunningApplication.runningApplications(withBundleIdentifier: Constants.secretAgentAppID) + NSRunningApplication.runningApplications(withBundleIdentifier: Bundle.main.agentBundleID) } // The process corresponding to this instance of Secretive @@ -37,10 +38,4 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { } -extension AgentStatusChecker { - enum Constants { - static let secretAgentAppID = "com.maxgoedjen.Secretive.SecretAgent" - } - -} diff --git a/Secretive/Controllers/LaunchAgentController.swift b/Secretive/Controllers/LaunchAgentController.swift index 97915f8..1f3ef5d 100644 --- a/Secretive/Controllers/LaunchAgentController.swift +++ b/Secretive/Controllers/LaunchAgentController.swift @@ -2,9 +2,10 @@ import Foundation import ServiceManagement import AppKit import OSLog +import SecretKit struct LaunchAgentController { - + 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(Bundle.main.agentBundleID as CFString, enabled) } } diff --git a/Secretive/Controllers/ShellConfigurationController.swift b/Secretive/Controllers/ShellConfigurationController.swift index 75b0614..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: "com.maxgoedjen.Secretive.Host", with: "com.maxgoedjen.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] { [ diff --git a/Secretive/Views/SecretDetailView.swift b/Secretive/Views/SecretDetailView.swift index 20fa76e..f8c7d12 100644 --- a/Secretive/Views/SecretDetailView.swift +++ b/Secretive/Views/SecretDetailView.swift @@ -25,9 +25,9 @@ struct SecretDetailView: View { } var dashedKeyName: String { - secret.name.replacingOccurrences(of: " ", with: "-") + secret.name.replacingOccurrences(of: " ", with: "-") } - + var dashedHostName: String { ["secretive", Host.current().localizedName, "local"] .compactMap { $0 }