secretive/SecretAgent/AppDelegate.swift

43 lines
1.2 KiB
Swift
Raw Normal View History

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
import SecretAgentKit
2020-03-22 01:43:26 +00:00
import Brief
2020-03-04 07:14:38 +00:00
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
2020-03-09 04:11:59 +00:00
let storeList: SecretStoreList = {
let list = SecretStoreList()
list.add(store: SecureEnclave.Store())
list.add(store: SmartCard.Store())
return list
}()
2020-03-22 01:43:26 +00:00
let updater = Updater()
2020-03-04 07:14:38 +00:00
let notifier = Notifier()
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
}()
lazy var socketController: SocketController = {
let path = (NSHomeDirectory() as NSString).appendingPathComponent("socket.ssh") as String
return SocketController(path: path)
}()
2020-03-22 01:43:26 +00:00
fileprivate var updateSink: AnyCancellable?
2020-03-04 07:14:38 +00:00
func applicationDidFinishLaunching(_ aNotification: Notification) {
os_log(.debug, "SecretAgent finished launching")
DispatchQueue.main.async {
self.socketController.handler = self.agent.handle(fileHandle:)
}
notifier.prompt()
2020-03-22 01:43:26 +00:00
updateSink = updater.$update.sink { release in
guard let release = release else { return }
self.notifier.notify(update: release)
}
2020-03-04 07:14:38 +00:00
}
}