made a Bundle extension in SecretKit with hostBundleID and agentBundleID properties

This commit is contained in:
Alex Lavallee 2020-12-27 17:07:56 -08:00
parent 670bfb17d5
commit edeb603ce0
No known key found for this signature in database
GPG Key ID: FF636FB2C9E94B03
4 changed files with 21 additions and 5 deletions

View File

@ -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"))!}
}

View File

@ -1,6 +1,7 @@
import Foundation import Foundation
import Combine import Combine
import AppKit import AppKit
import SecretKit
protocol AgentStatusCheckerProtocol: ObservableObject { protocol AgentStatusCheckerProtocol: ObservableObject {
var running: Bool { get } var running: Bool { get }
@ -9,7 +10,6 @@ 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")
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 ) NSRunningApplication.runningApplications(withBundleIdentifier: Bundle.main.agentBundleID)
} }
// The process corresponding to this instance of Secretive // The process corresponding to this instance of Secretive

View File

@ -2,10 +2,10 @@ import Foundation
import ServiceManagement import ServiceManagement
import AppKit import AppKit
import OSLog import OSLog
import SecretKit
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)
@ -33,7 +33,7 @@ struct LaunchAgentController {
} }
private func setEnabled(_ enabled: Bool) -> Bool { private func setEnabled(_ enabled: Bool) -> Bool {
SMLoginItemSetEnabled(bundleID as CFString, enabled) SMLoginItemSetEnabled(Bundle.main.agentBundleID as CFString, enabled)
} }
} }

View File

@ -1,9 +1,10 @@
import Foundation import Foundation
import Cocoa import Cocoa
import SecretKit
struct ShellConfigurationController { 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] { var shellInstructions: [ShellConfigInstruction] {
[ [