mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-10 19:47:24 +01:00
XPC scaffolding
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user