mirror of
				https://github.com/maxgoedjen/secretive.git
				synced 2025-11-04 09:20:56 +00:00 
			
		
		
		
	Lots of UI quality of life changes.
This commit is contained in:
		
							parent
							
								
									78dc4c0d93
								
							
						
					
					
						commit
						c2fc71d299
					
				@ -104,7 +104,7 @@ extension Release: Identifiable {
 | 
			
		||||
extension Release {
 | 
			
		||||
 | 
			
		||||
    public var critical: Bool {
 | 
			
		||||
        return body.contains(Constants.securityContent)
 | 
			
		||||
        body.contains(Constants.securityContent)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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<Updater, AgentStatusChecker>(runSetupBlock: { self.runSetup(sender: nil) })
 | 
			
		||||
            ContentView<Updater, AgentStatusChecker>()
 | 
			
		||||
                .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"
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,8 @@ struct LaunchAgentController {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    func relaunch() {
 | 
			
		||||
        _ = setEnabled(false)
 | 
			
		||||
        _ = setEnabled(true)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private func setEnabled(_ enabled: Bool) -> Bool {
 | 
			
		||||
 | 
			
		||||
@ -91,8 +91,12 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    func updateNotice() -> ToolbarItem<Void, AnyView> {
 | 
			
		||||
        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 {
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -43,14 +43,16 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: 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)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
@ -1,14 +1,10 @@
 | 
			
		||||
import SwiftUI
 | 
			
		||||
import Brief
 | 
			
		||||
 | 
			
		||||
//struct UpdateView<UpdaterType: UpdaterProtocol>: View {
 | 
			
		||||
//
 | 
			
		||||
//    
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
struct UpdateDetailView: View {
 | 
			
		||||
struct UpdateDetailView<UpdaterType: Updater>: 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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user