Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change hard-coded bundleID to automatically retrieved one #202

Merged
merged 15 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions SecretKit/Common/BundleIDs.swift
Original file line number Diff line number Diff line change
@@ -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"))!}
}
4 changes: 4 additions & 0 deletions Secretive.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -308,6 +309,7 @@
50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStoreView.swift; sourceTree = "<group>"; };
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 = "<group>"; };
FA0B34662599619E0013AB3A /* BundleIDs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleIDs.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -591,6 +593,7 @@
5068389F2415EA4F00F55094 /* Erasers */,
506838A42415EA6800F55094 /* OpenSSH */,
5068389D241471CD00F55094 /* SecretStoreList.swift */,
FA0B34662599619E0013AB3A /* BundleIDs.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
9 changes: 2 additions & 7 deletions Secretive/Controllers/AgentStatusChecker.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import Combine
import AppKit
import SecretKit

protocol AgentStatusCheckerProtocol: ObservableObject {
var running: Bool { get }
Expand All @@ -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
Expand All @@ -37,10 +38,4 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {

}

extension AgentStatusChecker {

enum Constants {
static let secretAgentAppID = "com.maxgoedjen.Secretive.SecretAgent"
}

}
5 changes: 3 additions & 2 deletions Secretive/Controllers/LaunchAgentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

}
3 changes: 2 additions & 1 deletion Secretive/Controllers/ShellConfigurationController.swift
Original file line number Diff line number Diff line change
@@ -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] {
[
Expand Down
4 changes: 2 additions & 2 deletions Secretive/Views/SecretDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ struct SecretDetailView<SecretType: Secret>: View {
}

var dashedKeyName: String {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this file got included by accident. Otherwise looks good. 🙏

secret.name.replacingOccurrences(of: " ", with: "-")
secret.name.replacingOccurrences(of: " ", with: "-")
}

var dashedHostName: String {
["secretive", Host.current().localizedName, "local"]
.compactMap { $0 }
Expand Down