diff --git a/Brief/Updater.swift b/Brief/Updater.swift index 101750b..a9b59a7 100644 --- a/Brief/Updater.swift +++ b/Brief/Updater.swift @@ -104,7 +104,7 @@ extension Release: Identifiable { extension Release { public var critical: Bool { - return body.contains(Constants.securityContent) + body.contains(Constants.securityContent) } } diff --git a/Secretive/App.swift b/Secretive/App.swift index 3d8d539..b4de2e6 100644 --- a/Secretive/App.swift +++ b/Secretive/App.swift @@ -16,56 +16,51 @@ struct AppDelegate: App { let agentStatusChecker = AgentStatusChecker() let justUpdatedChecker = JustUpdatedChecker() + @State var showingSetup = false + @AppStorage("defaultsHasRunSetup") var hasRunSetup = false + @SceneBuilder var body: some Scene { WindowGroup { - ContentView(runSetupBlock: { self.runSetup(sender: nil) }) + ContentView() .environmentObject(storeList) .environmentObject(updater) .environmentObject(agentStatusChecker) + .sheet(isPresented: $showingSetup) { + SetupView { completed in + self.showingSetup = false + self.hasRunSetup = completed + } + } + .onAppear { + if !hasRunSetup { + showingSetup = true + } + } } - WindowGroup { - SetupView() { _ in - print("Setup") + .commands { + CommandGroup(after: CommandGroupPlacement.newItem) { + Button("New Secret") { + // TODO: Add + } + .keyboardShortcut(KeyboardShortcut(KeyEquivalent("N"), modifiers: .command)) + } + CommandGroup(replacing: .help) { + Button("Help") { + NSWorkspace.shared.open(Constants.helpURL) + } + } + CommandGroup(after: .help) { + Button("Setup Secret Agent") { + self.showingSetup = true + } } } } } -extension AppDelegate { - - func runSetup(sender: AnyObject?) { - let setupWindow = NSWindow( - contentRect: NSRect(x: 0, y: 0, width: 0, height: 0), - styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], - backing: .buffered, defer: false) - let setupView = SetupView() { success in -// self.window.endSheet(setupWindow) - self.agentStatusChecker.check() - } - setupWindow.contentView = NSHostingView(rootView: setupView) -// window.beginSheet(setupWindow, completionHandler: nil) - } - - func runSetupIfNeeded() { - if !UserDefaults.standard.bool(forKey: Constants.defaultsHasRunSetup) { - UserDefaults.standard.set(true, forKey: Constants.defaultsHasRunSetup) - runSetup(sender: nil) - } - } - - func relaunchAgentIfNeeded() { - if agentStatusChecker.running && justUpdatedChecker.justUpdated { - LaunchAgentController().relaunch() - } - } +private enum Constants { + static let helpURL = URL(string: "https://github.com/maxgoedjen/secretive/blob/main/FAQ.md")! } -extension AppDelegate { - - enum Constants { - static let defaultsHasRunSetup = "defaultsHasRunSetup" - } - -} diff --git a/Secretive/Controllers/LaunchAgentController.swift b/Secretive/Controllers/LaunchAgentController.swift index 21b8a3e..8077da5 100644 --- a/Secretive/Controllers/LaunchAgentController.swift +++ b/Secretive/Controllers/LaunchAgentController.swift @@ -8,6 +8,8 @@ struct LaunchAgentController { } func relaunch() { + _ = setEnabled(false) + _ = setEnabled(true) } private func setEnabled(_ enabled: Bool) -> Bool { diff --git a/Secretive/Views/ContentView.swift b/Secretive/Views/ContentView.swift index cdf5366..f047f76 100644 --- a/Secretive/Views/ContentView.swift +++ b/Secretive/Views/ContentView.swift @@ -91,8 +91,12 @@ struct ContentView ToolbarItem { - let update = updater.update ?? Release(name: "", html_url: URL(string:"https://example.com")!, body: "") -// guard let update = updater.update else { fatalError() } +// let update = updater.update ?? Release(name: "", html_url: URL(string:"https://example.com")!, body: "") + guard let update = updater.update else { + return ToolbarItem { + AnyView(Spacer()) + } + } let color: Color let text: String if update.critical { diff --git a/Secretive/Views/CreateSecretView.swift b/Secretive/Views/CreateSecretView.swift index 3a206d6..29423cc 100644 --- a/Secretive/Views/CreateSecretView.swift +++ b/Secretive/Views/CreateSecretView.swift @@ -33,16 +33,14 @@ struct CreateSecretView: View { Spacer() } } - .onExitCommand(perform: dismissalBlock) } HStack { Spacer() - Button(action: dismissalBlock) { - Text("Cancel") - } - Button(action: save) { - Text("Create") - }.disabled(name.isEmpty) + Button("Cancel", action: dismissalBlock) + .keyboardShortcut(.cancelAction) + Button("Create", action: save) + .disabled(name.isEmpty) + .keyboardShortcut(.defaultAction) } }.padding() } diff --git a/Secretive/Views/DeleteSecretView.swift b/Secretive/Views/DeleteSecretView.swift index d0618ed..9b1ea92 100644 --- a/Secretive/Views/DeleteSecretView.swift +++ b/Secretive/Views/DeleteSecretView.swift @@ -43,14 +43,16 @@ struct DeleteSecretView: View { } HStack { Spacer() - Button(action: delete) { - Text("Delete") - }.disabled(confirm != secret.name) - Button(action: { self.dismissalBlock(false) }) { - Text("Don't Delete") + Button("Delete", action: delete) + .disabled(confirm != secret.name) + .keyboardShortcut(.delete) + Button("Don't Delete") { + self.dismissalBlock(false) } + .keyboardShortcut(.cancelAction) } - }.padding() + } + .padding() .frame(minWidth: 400) } diff --git a/Secretive/Views/UpdateView.swift b/Secretive/Views/UpdateView.swift index fafba04..5a04228 100644 --- a/Secretive/Views/UpdateView.swift +++ b/Secretive/Views/UpdateView.swift @@ -1,14 +1,10 @@ import SwiftUI import Brief -//struct UpdateView: View { -// -// -//} - -struct UpdateDetailView: View { +struct UpdateDetailView: View { private let update: Release + @EnvironmentObject var updater: UpdaterType init(update: Release) { self.update = update @@ -22,11 +18,19 @@ struct UpdateDetailView: View { attributedBody } } - Button(action: { - NSWorkspace.shared.open(update.html_url) - }, label: { - Text("Update") - }) + HStack { + if !update.critical { + Button("Ignore") { + updater.ignore(release: update) + } + Spacer() + } + Button("Update") { + NSWorkspace.shared.open(update.html_url) + } + .keyboardShortcut(.defaultAction) + } + } .padding() .frame(maxWidth: 500)