UI tweaks

This commit is contained in:
Max Goedjen
2026-06-19 23:24:53 -07:00
parent 76baba746c
commit 702e3f2cb0
4 changed files with 118 additions and 290 deletions

View File

@@ -1,15 +1,31 @@
import SwiftUI
import ServiceManagement
@unsafe @preconcurrency import ServiceManagement
import SecretKit
import SecureEnclaveSecretKit
import SmartCardSecretKit
import Brief
import CertificateKit
@Observable
final class LaunchService: Sendable {
private let service = SMAppService.agent(plistName: "com.maxgoedjen.Secretive.SecretAgent.plist")
var status: SMAppService.Status {
service.status
}
func configure() {
try? service.unregister()
try! service.register()
}
func disable() {
try? service.unregister()
}
}
@main
struct Secretive: App {
// @Environment(\.agentLaunchController) var agentLaunchController
@Environment(\.justUpdatedChecker) var justUpdatedChecker
@SceneBuilder var body: some Scene {
@@ -17,13 +33,8 @@ struct Secretive: App {
ContentView()
.environment(EnvironmentValues._secretStoreList)
.environment(EnvironmentValues._certificateStore)
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
Task {
let service = SMAppService.agent(plistName: "com.maxgoedjen.Secretive.SecretAgent.plist")
try? service.unregister()
try! service.register()
print("Status: \(service.status)")
}
.onAppear {
EnvironmentValues._launchService.configure()
}
}
.commands {
@@ -111,6 +122,9 @@ extension EnvironmentValues {
private static let _justUpdatedChecker = JustUpdatedChecker()
@Entry var justUpdatedChecker: any JustUpdatedCheckerProtocol = _justUpdatedChecker
fileprivate static let _launchService = LaunchService()
@Entry var launchService: LaunchService = _launchService
@MainActor var secretStoreList: SecretStoreList {
EnvironmentValues._secretStoreList
}

View File

@@ -2,10 +2,10 @@ import SwiftUI
struct AgentStatusView: View {
@Environment(\.agentLaunchController) private var agentLaunchController: any AgentLaunchControllerProtocol
@Environment(\.launchService) private var launchService
var body: some View {
if agentLaunchController.running {
if launchService.status == .enabled {
AgentRunningView()
} else {
AgentNotRunningView()
@@ -14,54 +14,53 @@ struct AgentStatusView: View {
}
struct AgentRunningView: View {
@Environment(\.agentLaunchController) private var agentLaunchController: any AgentLaunchControllerProtocol
@Environment(\.launchService) private var launchService
@AppStorage("explicitlyDisabled") var explicitlyDisabled = false
var body: some View {
Form {
Section {
if let process = agentLaunchController.process {
ConfigurationItemView(
title: .agentDetailsLocationTitle,
value: process.bundleURL!.path(),
action: .revealInFinder(process.bundleURL!.path()),
)
// if let process = agentLaunchController.process {
// ConfigurationItemView(
// title: .agentDetailsLocationTitle,
// value: process.bundleURL!.path(),
// action: .revealInFinder(process.bundleURL!.path()),
// )
ConfigurationItemView(
title: .agentDetailsSocketPathTitle,
value: URL.socketPath,
action: .copy(URL.socketPath),
)
ConfigurationItemView(
title: .agentDetailsVersionTitle,
value: Bundle(url: process.bundleURL!)!.infoDictionary!["CFBundleShortVersionString"] as! String
)
if let launchDate = process.launchDate {
ConfigurationItemView(
title: .agentDetailsRunningSinceTitle,
value: launchDate.formatted()
)
}
}
// ConfigurationItemView(
// title: .agentDetailsVersionTitle,
// value: Bundle(url: process.bundleURL!)!.infoDictionary!["CFBundleShortVersionString"] as! String
// )
// if let launchDate = process.launchDate {
// ConfigurationItemView(
// title: .agentDetailsRunningSinceTitle,
// value: launchDate.formatted()
// )
// }
// }
} header: {
Text(.agentRunningNoticeDetailTitle)
Text(.agentReadyNoticeDetailTitle)
.font(.headline)
.padding(.top)
} footer: {
VStack(alignment: .leading, spacing: 10) {
Text(.agentRunningNoticeDetailDescription)
Text(.agentReadyNoticeDetailDescription)
HStack {
Spacer()
Menu(.agentDetailsRestartAgentButton) {
Button(.agentDetailsDisableAgentButton) {
Task {
explicitlyDisabled = true
try? await agentLaunchController
.uninstall()
launchService.disable()
}
}
} primaryAction: {
Task {
try? await agentLaunchController.forceLaunch()
launchService.configure()
}
}
}
@@ -78,7 +77,6 @@ struct AgentRunningView: View {
struct AgentNotRunningView: View {
@Environment(\.agentLaunchController) private var agentLaunchController
@State var triedRestart = false
@State var loading = false
@AppStorage("explicitlyDisabled") var explicitlyDisabled = false
@@ -87,12 +85,12 @@ struct AgentNotRunningView: View {
Form {
Section {
} header: {
Text(.agentNotRunningNoticeTitle)
Text(.agentNotConfiguredNoticeTitle)
.font(.headline)
.padding(.top)
} footer: {
VStack(alignment: .leading, spacing: 10) {
Text(.agentNotRunningNoticeDetailDescription)
Text(.agentNotConfiguredNoticeDetailDescription)
HStack {
if !triedRestart {
Spacer()

View File

@@ -19,6 +19,7 @@ struct ContentView: View {
@Environment(\.certificateStore) private var certificateStore
@Environment(\.updater) private var updater
@Environment(\.agentLaunchController) private var agentLaunchController
@Environment(\.launchService) private var launchService
@AppStorage("defaultsHasRunSetup") private var hasRunSetup = false
@State private var showingCreation = false
@@ -147,15 +148,15 @@ extension ContentView {
showingAgentInfo = true
}, label: {
HStack {
if agentLaunchController.running {
Text(.agentRunningNoticeTitle)
if launchService.status == .enabled {
Text(.agentReadyNoticeTitle)
.font(.headline)
.foregroundColor(colorScheme == .light ? Color(white: 0.3) : .white)
Circle()
.frame(width: 10, height: 10)
.foregroundColor(Color.green)
} else {
Text(.agentNotRunningNoticeTitle)
Text(.agentNotConfiguredNoticeTitle)
.font(.headline)
Circle()
.frame(width: 10, height: 10)
@@ -165,8 +166,8 @@ extension ContentView {
})
.buttonStyle(
ToolbarStatusButtonStyle(
lightColor: agentLaunchController.running ? .black.opacity(0.05) : .red.opacity(0.75),
darkColor: agentLaunchController.running ? .white.opacity(0.05) : .red.opacity(0.5),
lightColor: launchService.status == .enabled ? .black.opacity(0.05) : .red.opacity(0.75),
darkColor: launchService.status == .enabled ? .white.opacity(0.05) : .red.opacity(0.5),
)
)
.popover(isPresented: $showingAgentInfo, attachmentAnchor: attachmentAnchor, arrowEdge: .bottom) {