mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-10 11:37:23 +01:00
XPC scaffolding
This commit is contained in:
@@ -7,8 +7,11 @@ import SmartCardSecretKit
|
||||
import SecretAgentKit
|
||||
import Brief
|
||||
|
||||
import SecretKit
|
||||
import SecretAgentKitProtocol
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, AgentProtocol {
|
||||
|
||||
private let storeList: SecretStoreList = {
|
||||
let list = SecretStoreList()
|
||||
@@ -27,9 +30,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
return SocketController(path: path)
|
||||
}()
|
||||
private var updateSink: AnyCancellable?
|
||||
private let logger = Logger()
|
||||
var delegate: ServiceDelegate? = nil
|
||||
let listener = NSXPCListener(machServiceName: Bundle.main.bundleIdentifier!)
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
Logger().debug("SecretAgent finished launching")
|
||||
logger.debug("SecretAgent finished launching")
|
||||
DispatchQueue.main.async {
|
||||
self.socketController.handler = self.agent.handle(reader:writer:)
|
||||
}
|
||||
@@ -39,13 +45,37 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
guard let update = update else { return }
|
||||
self.notifier.notify(update: update, ignore: self.updater.ignore(release:))
|
||||
}
|
||||
connect()
|
||||
}
|
||||
|
||||
func reloadKeys() {
|
||||
// TODO: This
|
||||
// storeList.reloadAll()
|
||||
try? publicKeyFileStoreController.generatePublicKeys(for: storeList.stores.flatMap({ $0.secrets }), clear: true)
|
||||
func connect() {
|
||||
delegate = ServiceDelegate(exportedObject: self)
|
||||
listener.delegate = delegate
|
||||
listener.resume()
|
||||
}
|
||||
|
||||
func updatedStore(withID id: UUID) async throws {
|
||||
logger.debug("Reloading keys for store with id: \(id)")
|
||||
guard let store = storeList.modifiableStore, store.id == id else { throw AgentProtocolStoreNotFoundError() }
|
||||
try store.reload()
|
||||
try publicKeyFileStoreController.generatePublicKeys(for: storeList.stores.flatMap({ $0.secrets }), clear: true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ServiceDelegate: NSObject, NSXPCListenerDelegate {
|
||||
|
||||
let exported: AgentProtocol
|
||||
|
||||
init(exportedObject: AgentProtocol) {
|
||||
self.exported = exportedObject
|
||||
}
|
||||
|
||||
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
|
||||
newConnection.exportedInterface = NSXPCInterface(with: AgentProtocol.self)
|
||||
newConnection.exportedObject = exported
|
||||
newConnection.resume()
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>$(TeamIdentifierPrefix)com.maxgoedjen.secretive</string>
|
||||
</array>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
<key>com.apple.security.smartcard</key>
|
||||
|
||||
Reference in New Issue
Block a user