XPC scaffolding

This commit is contained in:
Max Goedjen
2022-01-02 22:15:18 -08:00
parent 98bf285ad2
commit d80d2ca656
18 changed files with 191 additions and 58 deletions

View File

@@ -0,0 +1,36 @@
import Foundation
import Combine
import AppKit
import SecretKit
import SecretAgentKitProtocol
protocol AgentCommunicationControllerProtocol: ObservableObject {
var agent: AgentProtocol { get }
}
class AgentCommunicationController: ObservableObject, AgentCommunicationControllerProtocol {
let agent: AgentProtocol
private let connection: NSXPCConnection
private var running = false
init() {
connection = NSXPCConnection(machServiceName: Bundle.main.agentBundleID)
connection.remoteObjectInterface = NSXPCInterface(with: AgentProtocol.self)
connection.invalidationHandler = {
print("INVALID")
}
agent = connection.remoteObjectProxyWithErrorHandler({ x in
print(x)
}) as! AgentProtocol
}
func configure() {
guard !running else { return }
running = true
connection.resume()
}
}

View File

@@ -4,7 +4,7 @@ import AppKit
import OSLog
import SecretKit
struct LaunchAgentController {
struct AgentLaunchController {
func install(completion: (() -> Void)? = nil) {
Logger().debug("Installing agent")
@@ -20,7 +20,7 @@ struct LaunchAgentController {
}
func forceLaunch(completion: ((Bool) -> Void)?) {
Logger().debug("Agent is not running, attempting to force launch")
Logger().debug("Agent is still not running, attempting to force launch")
let url = Bundle.main.bundleURL.appendingPathComponent("Contents/Library/LoginItems/SecretAgent.app")
let config = NSWorkspace.OpenConfiguration()
config.activates = false

View File

@@ -9,6 +9,7 @@ protocol JustUpdatedCheckerProtocol: ObservableObject {
class JustUpdatedChecker: ObservableObject, JustUpdatedCheckerProtocol {
@Published var justUpdated: Bool = false
var alreadyRelaunchedForDebug = false
init() {
check()
@@ -18,7 +19,12 @@ class JustUpdatedChecker: ObservableObject, JustUpdatedCheckerProtocol {
let lastBuild = UserDefaults.standard.object(forKey: Constants.previousVersionUserDefaultsKey) as? String ?? "None"
let currentBuild = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
UserDefaults.standard.set(currentBuild, forKey: Constants.previousVersionUserDefaultsKey)
justUpdated = lastBuild != currentBuild
if currentBuild != Constants.debugVersionKey {
justUpdated = lastBuild != currentBuild
} else {
justUpdated = !alreadyRelaunchedForDebug
alreadyRelaunchedForDebug = true
}
}
@@ -29,6 +35,7 @@ extension JustUpdatedChecker {
enum Constants {
static let previousVersionUserDefaultsKey = "com.maxgoedjen.Secretive.lastBuild"
static let debugVersionKey = "GITHUB_CI_VERSION"
}
}