Lots of UI quality of life changes.

This commit is contained in:
Max Goedjen 2020-09-10 23:07:31 -07:00
parent 78dc4c0d93
commit c2fc71d299
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
7 changed files with 70 additions and 65 deletions

View File

@ -104,7 +104,7 @@ extension Release: Identifiable {
extension Release { extension Release {
public var critical: Bool { public var critical: Bool {
return body.contains(Constants.securityContent) body.contains(Constants.securityContent)
} }
} }

View File

@ -16,56 +16,51 @@ struct AppDelegate: App {
let agentStatusChecker = AgentStatusChecker() let agentStatusChecker = AgentStatusChecker()
let justUpdatedChecker = JustUpdatedChecker() let justUpdatedChecker = JustUpdatedChecker()
@State var showingSetup = false
@AppStorage("defaultsHasRunSetup") var hasRunSetup = false
@SceneBuilder var body: some Scene { @SceneBuilder var body: some Scene {
WindowGroup { WindowGroup {
ContentView<Updater, AgentStatusChecker>(runSetupBlock: { self.runSetup(sender: nil) }) ContentView<Updater, AgentStatusChecker>()
.environmentObject(storeList) .environmentObject(storeList)
.environmentObject(updater) .environmentObject(updater)
.environmentObject(agentStatusChecker) .environmentObject(agentStatusChecker)
.sheet(isPresented: $showingSetup) {
SetupView { completed in
self.showingSetup = false
self.hasRunSetup = completed
}
}
.onAppear {
if !hasRunSetup {
showingSetup = true
}
}
}
.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
} }
WindowGroup {
SetupView() { _ in
print("Setup")
} }
} }
} }
} }
extension AppDelegate {
func runSetup(sender: AnyObject?) { private enum Constants {
let setupWindow = NSWindow( static let helpURL = URL(string: "https://github.com/maxgoedjen/secretive/blob/main/FAQ.md")!
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()
}
}
}
extension AppDelegate {
enum Constants {
static let defaultsHasRunSetup = "defaultsHasRunSetup"
}
}

View File

@ -8,6 +8,8 @@ struct LaunchAgentController {
} }
func relaunch() { func relaunch() {
_ = setEnabled(false)
_ = setEnabled(true)
} }
private func setEnabled(_ enabled: Bool) -> Bool { private func setEnabled(_ enabled: Bool) -> Bool {

View File

@ -91,8 +91,12 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
} }
func updateNotice() -> ToolbarItem<Void, AnyView> { func updateNotice() -> ToolbarItem<Void, AnyView> {
let update = updater.update ?? Release(name: "", html_url: URL(string:"https://example.com")!, body: "") // let update = updater.update ?? Release(name: "", html_url: URL(string:"https://example.com")!, body: "")
// guard let update = updater.update else { fatalError() } guard let update = updater.update else {
return ToolbarItem {
AnyView(Spacer())
}
}
let color: Color let color: Color
let text: String let text: String
if update.critical { if update.critical {

View File

@ -33,16 +33,14 @@ struct CreateSecretView: View {
Spacer() Spacer()
} }
} }
.onExitCommand(perform: dismissalBlock)
} }
HStack { HStack {
Spacer() Spacer()
Button(action: dismissalBlock) { Button("Cancel", action: dismissalBlock)
Text("Cancel") .keyboardShortcut(.cancelAction)
} Button("Create", action: save)
Button(action: save) { .disabled(name.isEmpty)
Text("Create") .keyboardShortcut(.defaultAction)
}.disabled(name.isEmpty)
} }
}.padding() }.padding()
} }

View File

@ -43,14 +43,16 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
} }
HStack { HStack {
Spacer() Spacer()
Button(action: delete) { Button("Delete", action: delete)
Text("Delete") .disabled(confirm != secret.name)
}.disabled(confirm != secret.name) .keyboardShortcut(.delete)
Button(action: { self.dismissalBlock(false) }) { Button("Don't Delete") {
Text("Don't Delete") self.dismissalBlock(false)
}
.keyboardShortcut(.cancelAction)
} }
} }
}.padding() .padding()
.frame(minWidth: 400) .frame(minWidth: 400)
} }

View File

@ -1,14 +1,10 @@
import SwiftUI import SwiftUI
import Brief import Brief
//struct UpdateView<UpdaterType: UpdaterProtocol>: View { struct UpdateDetailView<UpdaterType: Updater>: View {
//
//
//}
struct UpdateDetailView: View {
private let update: Release private let update: Release
@EnvironmentObject var updater: UpdaterType
init(update: Release) { init(update: Release) {
self.update = update self.update = update
@ -22,11 +18,19 @@ struct UpdateDetailView: View {
attributedBody attributedBody
} }
} }
Button(action: { HStack {
if !update.critical {
Button("Ignore") {
updater.ignore(release: update)
}
Spacer()
}
Button("Update") {
NSWorkspace.shared.open(update.html_url) NSWorkspace.shared.open(update.html_url)
}, label: { }
Text("Update") .keyboardShortcut(.defaultAction)
}) }
} }
.padding() .padding()
.frame(maxWidth: 500) .frame(maxWidth: 500)