2020-03-04 07:14:38 +00:00
|
|
|
import Cocoa
|
2020-03-22 01:43:26 +00:00
|
|
|
import OSLog
|
|
|
|
import Combine
|
2020-03-04 07:14:38 +00:00
|
|
|
import SecretKit
|
2022-01-02 00:43:29 +00:00
|
|
|
import SecureEnclaveSecretKit
|
|
|
|
import SmartCardSecretKit
|
2020-03-17 06:39:34 +00:00
|
|
|
import SecretAgentKit
|
2020-03-22 01:43:26 +00:00
|
|
|
import Brief
|
2025-01-06 00:07:11 +00:00
|
|
|
import Observation
|
2020-03-04 07:14:38 +00:00
|
|
|
|
2024-12-25 23:25:01 +00:00
|
|
|
@main
|
2020-03-04 07:14:38 +00:00
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
|
2020-09-22 06:12:50 +00:00
|
|
|
private let storeList: SecretStoreList = {
|
2020-03-09 04:11:59 +00:00
|
|
|
let list = SecretStoreList()
|
|
|
|
list.add(store: SecureEnclave.Store())
|
|
|
|
list.add(store: SmartCard.Store())
|
|
|
|
return list
|
|
|
|
}()
|
2020-09-22 06:12:50 +00:00
|
|
|
private let updater = Updater(checkOnLaunch: false)
|
|
|
|
private let notifier = Notifier()
|
2022-01-03 07:25:40 +00:00
|
|
|
private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: NSHomeDirectory())
|
2020-09-22 06:12:50 +00:00
|
|
|
private lazy var agent: Agent = {
|
2020-03-17 07:56:55 +00:00
|
|
|
Agent(storeList: storeList, witness: notifier)
|
2020-03-04 07:14:38 +00:00
|
|
|
}()
|
2020-09-22 06:12:50 +00:00
|
|
|
private lazy var socketController: SocketController = {
|
2020-03-04 07:14:38 +00:00
|
|
|
let path = (NSHomeDirectory() as NSString).appendingPathComponent("socket.ssh") as String
|
|
|
|
return SocketController(path: path)
|
|
|
|
}()
|
2020-05-16 06:19:00 +00:00
|
|
|
private var updateSink: AnyCancellable?
|
2023-12-11 08:59:30 +00:00
|
|
|
private let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "AppDelegate")
|
2020-03-04 07:14:38 +00:00
|
|
|
|
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
2023-12-11 08:59:30 +00:00
|
|
|
logger.debug("SecretAgent finished launching")
|
2025-01-06 00:07:11 +00:00
|
|
|
Task { @MainActor in
|
|
|
|
socketController.handler = { [agent] reader, writer in
|
|
|
|
await agent.handle(reader: reader, writer: writer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Task {
|
|
|
|
for await _ in NotificationCenter.default.notifications(named: .secretStoreReloaded) {
|
|
|
|
try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true)
|
|
|
|
}
|
|
|
|
}
|
2022-12-22 04:18:27 +00:00
|
|
|
try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true)
|
2020-03-04 07:14:38 +00:00
|
|
|
notifier.prompt()
|
2025-01-06 00:07:11 +00:00
|
|
|
_ = withObservationTracking {
|
|
|
|
updater.update
|
|
|
|
} onChange: { [updater, notifier] in
|
|
|
|
notifier.notify(update: updater.update!) { release in
|
|
|
|
Task {
|
|
|
|
await updater.ignore(release: release)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
2025-01-06 00:07:11 +00:00
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
|
|
|
|