mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-25 06:57:07 +00:00
a530a83e87
fix:Non-constant range: argument must be an integer literal fix:Generic parameter 'ValueType' shadows generic parameter from outer scope with the same name; this is an error fix:Converting non-sendable function value to '@Sendable (any FileHandleReader, any FileHandleWriter) async -> Bool' may introduce data races
53 lines
2.0 KiB
Swift
53 lines
2.0 KiB
Swift
import Cocoa
|
|
import OSLog
|
|
import Combine
|
|
import SecretKit
|
|
import SecureEnclaveSecretKit
|
|
import SmartCardSecretKit
|
|
import SecretAgentKit
|
|
import Brief
|
|
|
|
@NSApplicationMain
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
private let storeList: SecretStoreList = {
|
|
let list = SecretStoreList()
|
|
list.add(store: SecureEnclave.Store())
|
|
list.add(store: SmartCard.Store())
|
|
return list
|
|
}()
|
|
private let updater = Updater(checkOnLaunch: false)
|
|
private let notifier = Notifier()
|
|
private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: NSHomeDirectory())
|
|
private lazy var agent: Agent = {
|
|
Agent(storeList: storeList, witness: notifier)
|
|
}()
|
|
private lazy var socketController: SocketController = {
|
|
let path = (NSHomeDirectory() as NSString).appendingPathComponent("socket.ssh") as String
|
|
return SocketController(path: path)
|
|
}()
|
|
private var updateSink: AnyCancellable?
|
|
private let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "AppDelegate")
|
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
|
logger.debug("SecretAgent finished launching")
|
|
DispatchQueue.main.async {
|
|
self.socketController.handler = { [weak self] reader, writer in
|
|
guard let self = self else { return false }
|
|
return await self.agent.handle(reader: reader, writer: writer)
|
|
}
|
|
}
|
|
NotificationCenter.default.addObserver(forName: .secretStoreReloaded, object: nil, queue: .main) { [self] _ in
|
|
try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true)
|
|
}
|
|
try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true)
|
|
notifier.prompt()
|
|
updateSink = updater.$update.sink { update in
|
|
guard let update = update else { return }
|
|
self.notifier.notify(update: update, ignore: self.updater.ignore(release:))
|
|
}
|
|
}
|
|
|
|
}
|
|
|