From f6f5e98302c8793ba3920db25f06b4efd8406657 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Mon, 1 Sep 2025 20:28:47 -0700 Subject: [PATCH] POC --- Sources/Packages/Localizable.xcstrings | 4 + Sources/SecretAgent/AppDelegate.swift | 128 ++++++++++-------- Sources/Secretive.xcodeproj/project.pbxproj | 10 ++ Sources/Secretive/App.swift | 5 - Sources/Secretive/Views/AgentStatusView.swift | 18 +-- 5 files changed, 97 insertions(+), 68 deletions(-) diff --git a/Sources/Packages/Localizable.xcstrings b/Sources/Packages/Localizable.xcstrings index f959af0..fafe143 100644 --- a/Sources/Packages/Localizable.xcstrings +++ b/Sources/Packages/Localizable.xcstrings @@ -4270,6 +4270,7 @@ } }, "Setup" : { + "extractionState" : "stale", "localizations" : { "en" : { "stringUnit" : { @@ -5199,6 +5200,9 @@ } } } + }, + "Test" : { + }, "unnamed_secret" : { "extractionState" : "manual", diff --git a/Sources/SecretAgent/AppDelegate.swift b/Sources/SecretAgent/AppDelegate.swift index 877145e..0a2832d 100644 --- a/Sources/SecretAgent/AppDelegate.swift +++ b/Sources/SecretAgent/AppDelegate.swift @@ -6,65 +6,85 @@ import SmartCardSecretKit import SecretAgentKit import Brief import Observation +import SwiftUI + + +extension EnvironmentValues { + private static let _agentStatusChecker = AgentStatusChecker() + @Entry var agentStatusChecker: any AgentStatusCheckerProtocol = _agentStatusChecker +} @main -class AppDelegate: NSObject, NSApplicationDelegate { +struct SecretAgent: App { - @MainActor private let storeList: SecretStoreList = { - let list = SecretStoreList() - let cryptoKit = SecureEnclave.Store() - let migrator = SecureEnclave.CryptoKitMigrator() - try? migrator.migrate(to: cryptoKit) - list.add(store: cryptoKit) - list.add(store: SmartCard.Store()) - return list - }() - private let updater = Updater(checkOnLaunch: true) - private let notifier = Notifier() - private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: URL.homeDirectory) - 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 let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "AppDelegate") - - func applicationDidFinishLaunching(_ aNotification: Notification) { - logger.debug("SecretAgent finished launching") - Task { - for await session in socketController.sessions { - Task { - do { - for await message in session.messages { - let agentResponse = try await agent.handle(data: message, provenance: session.provenance) - try await session.write(agentResponse) - } - } catch { - try session.close() - } - } - } - } - Task { - for await _ in NotificationCenter.default.notifications(named: .secretStoreReloaded) { - try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true) - } - } - try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true) - notifier.prompt() - _ = withObservationTracking { - updater.update - } onChange: { [updater, notifier] in - Task { - guard !updater.testBuild else { return } - await notifier.notify(update: updater.update!) { release in - await updater.ignore(release: release) - } - } + @SceneBuilder var body: some Scene { + MenuBarExtra("Test", systemImage: "lock") { + AgentStatusView() + .fixedSize() } + .menuBarExtraStyle(.window) } } +//@main +//class AppDelegate: NSObject, NSApplicationDelegate { +// +// @MainActor private let storeList: SecretStoreList = { +// let list = SecretStoreList() +// let cryptoKit = SecureEnclave.Store() +// let migrator = SecureEnclave.CryptoKitMigrator() +// try? migrator.migrate(to: cryptoKit) +// list.add(store: cryptoKit) +// list.add(store: SmartCard.Store()) +// return list +// }() +// private let updater = Updater(checkOnLaunch: true) +// private let notifier = Notifier() +// private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: URL.homeDirectory) +// 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 let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "AppDelegate") +// +// func applicationDidFinishLaunching(_ aNotification: Notification) { +// logger.debug("SecretAgent finished launching") +// Task { +// for await session in socketController.sessions { +// Task { +// do { +// for await message in session.messages { +// let agentResponse = try await agent.handle(data: message, provenance: session.provenance) +// try await session.write(agentResponse) +// } +// } catch { +// try session.close() +// } +// } +// } +// } +// Task { +// for await _ in NotificationCenter.default.notifications(named: .secretStoreReloaded) { +// try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true) +// } +// } +// try? publicKeyFileStoreController.generatePublicKeys(for: storeList.allSecrets, clear: true) +// notifier.prompt() +// _ = withObservationTracking { +// updater.update +// } onChange: { [updater, notifier] in +// Task { +// guard !updater.testBuild else { return } +// await notifier.notify(update: updater.update!) { release in +// await updater.ignore(release: release) +// } +// } +// } +// } +// +//} +// diff --git a/Sources/Secretive.xcodeproj/project.pbxproj b/Sources/Secretive.xcodeproj/project.pbxproj index 029fe62..e1527c0 100644 --- a/Sources/Secretive.xcodeproj/project.pbxproj +++ b/Sources/Secretive.xcodeproj/project.pbxproj @@ -33,6 +33,11 @@ 50617D8723FCE48E0099B055 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50617D8623FCE48E0099B055 /* Assets.xcassets */; }; 50617D8A23FCE48E0099B055 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50617D8923FCE48E0099B055 /* Preview Assets.xcassets */; }; 50617DD223FCEFA90099B055 /* PreviewStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50617DD123FCEFA90099B055 /* PreviewStore.swift */; }; + 5064ADD32E669B1100B1382C /* AgentStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50BDCB712E63BAF20072D2E7 /* AgentStatusView.swift */; }; + 5064ADD42E669B2300B1382C /* AgentStatusChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */; }; + 5064ADD52E669B3000B1382C /* BundleIDs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50033AC227813F1700253856 /* BundleIDs.swift */; }; + 5064ADD62E669B5F00B1382C /* LaunchAgentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50571E0424393D1500F76F6C /* LaunchAgentController.swift */; }; + 5064ADD72E669B7E00B1382C /* ConfigurationItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50BDCB752E6450950072D2E7 /* ConfigurationItemView.swift */; }; 5065E313295517C500E16645 /* ToolbarButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5065E312295517C500E16645 /* ToolbarButtonStyle.swift */; }; 5066A6C22516F303004B5A36 /* SetupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5066A6C12516F303004B5A36 /* SetupView.swift */; }; 5066A6C82516FE6E004B5A36 /* CopyableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5066A6C72516FE6E004B5A36 /* CopyableView.swift */; }; @@ -476,8 +481,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5064ADD32E669B1100B1382C /* AgentStatusView.swift in Sources */, + 5064ADD72E669B7E00B1382C /* ConfigurationItemView.swift in Sources */, 50020BB024064869003D4025 /* AppDelegate.swift in Sources */, + 5064ADD52E669B3000B1382C /* BundleIDs.swift in Sources */, 5018F54F24064786002EB505 /* Notifier.swift in Sources */, + 5064ADD62E669B5F00B1382C /* LaunchAgentController.swift in Sources */, + 5064ADD42E669B2300B1382C /* AgentStatusChecker.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/Secretive/App.swift b/Sources/Secretive/App.swift index b2db3af..93ecf03 100644 --- a/Sources/Secretive/App.swift +++ b/Sources/Secretive/App.swift @@ -80,11 +80,6 @@ struct Secretive: App { NSWorkspace.shared.open(Constants.helpURL) } } - CommandGroup(after: .help) { - Button("Setup") { - showingSetup = true - } - } SidebarCommands() } } diff --git a/Sources/Secretive/Views/AgentStatusView.swift b/Sources/Secretive/Views/AgentStatusView.swift index d89fca9..28f69a0 100644 --- a/Sources/Secretive/Views/AgentStatusView.swift +++ b/Sources/Secretive/Views/AgentStatusView.swift @@ -127,7 +127,7 @@ struct AgentNotRunningView: View { } } } - .primaryButton() +// .primaryButton() } else { Text(.agentDetailsCouldNotStartError) .bold() @@ -144,11 +144,11 @@ struct AgentNotRunningView: View { } -#Preview { - AgentStatusView() - .environment(\.agentStatusChecker, PreviewAgentStatusChecker(running: false)) -} -#Preview { - AgentStatusView() - .environment(\.agentStatusChecker, PreviewAgentStatusChecker(running: true, process: .current)) -} +//#Preview { +// AgentStatusView() +// .environment(\.agentStatusChecker, PreviewAgentStatusChecker(running: false)) +//} +//#Preview { +// AgentStatusView() +// .environment(\.agentStatusChecker, PreviewAgentStatusChecker(running: true, process: .current)) +//}