mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-18 05:22:11 +00:00
Switch to env objects
This commit is contained in:
parent
31c8d43301
commit
78dc4c0d93
@ -3,85 +3,6 @@ import SwiftUI
|
|||||||
import SecretKit
|
import SecretKit
|
||||||
import Brief
|
import Brief
|
||||||
|
|
||||||
//@NSApplicationMain
|
|
||||||
//class AppDelegate: NSObject, NSApplicationDelegate {
|
|
||||||
//
|
|
||||||
// var window: NSWindow!
|
|
||||||
// @IBOutlet var newMenuItem: NSMenuItem!
|
|
||||||
// @IBOutlet var toolbar: NSToolbar!
|
|
||||||
// let storeList: SecretStoreList = {
|
|
||||||
// let list = SecretStoreList()
|
|
||||||
// list.add(store: SecureEnclave.Store())
|
|
||||||
// list.add(store: SmartCard.Store())
|
|
||||||
// return list
|
|
||||||
// }()
|
|
||||||
// let updater = Updater()
|
|
||||||
// let agentStatusChecker = AgentStatusChecker()
|
|
||||||
// let justUpdatedChecker = JustUpdatedChecker()
|
|
||||||
//
|
|
||||||
// func applicationDidFinishLaunching(_ aNotification: Notification) {
|
|
||||||
// let contentView = ContentView(storeList: storeList, updater: updater, agentStatusChecker: agentStatusChecker, runSetupBlock: { self.runSetup(sender: nil) })
|
|
||||||
// // Create the window and set the content view.
|
|
||||||
// window = NSWindow(
|
|
||||||
// contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
|
||||||
// styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
|
||||||
// backing: .buffered, defer: false)
|
|
||||||
// window.center()
|
|
||||||
// window.setFrameAutosaveName("Main Window")
|
|
||||||
// window.contentView = NSHostingView(rootView: contentView)
|
|
||||||
// window.makeKeyAndOrderFront(nil)
|
|
||||||
// window.titleVisibility = .hidden
|
|
||||||
// window.toolbar = toolbar
|
|
||||||
// window.isReleasedWhenClosed = false
|
|
||||||
// if storeList.modifiableStore?.isAvailable ?? false {
|
|
||||||
// let plus = NSTitlebarAccessoryViewController()
|
|
||||||
// plus.view = NSButton(image: NSImage(named: NSImage.addTemplateName)!, target: self, action: #selector(add(sender:)))
|
|
||||||
// plus.layoutAttribute = .right
|
|
||||||
// window.addTitlebarAccessoryViewController(plus)
|
|
||||||
// newMenuItem.isEnabled = true
|
|
||||||
// }
|
|
||||||
// runSetupIfNeeded()
|
|
||||||
// relaunchAgentIfNeeded()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func applicationDidBecomeActive(_ notification: Notification) {
|
|
||||||
// agentStatusChecker.check()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
||||||
// guard !flag else { return false }
|
|
||||||
// window.makeKeyAndOrderFront(self)
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @IBAction func add(sender: AnyObject?) {
|
|
||||||
// var addWindow: NSWindow!
|
|
||||||
// let addView = CreateSecretView(store: storeList.modifiableStore!) {
|
|
||||||
// self.window.endSheet(addWindow)
|
|
||||||
// }
|
|
||||||
// addWindow = NSWindow(
|
|
||||||
// contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
|
||||||
// styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
|
||||||
// backing: .buffered, defer: false)
|
|
||||||
// addWindow.contentView = NSHostingView(rootView: addView)
|
|
||||||
// window.beginSheet(addWindow, completionHandler: nil)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @IBAction 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)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
||||||
@main
|
@main
|
||||||
struct AppDelegate: App {
|
struct AppDelegate: App {
|
||||||
|
|
||||||
@ -97,7 +18,10 @@ struct AppDelegate: App {
|
|||||||
|
|
||||||
@SceneBuilder var body: some Scene {
|
@SceneBuilder var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView(storeList: storeList, updater: updater, agentStatusChecker: agentStatusChecker, runSetupBlock: { self.runSetup(sender: nil) })
|
ContentView<Updater, AgentStatusChecker>(runSetupBlock: { self.runSetup(sender: nil) })
|
||||||
|
.environmentObject(storeList)
|
||||||
|
.environmentObject(updater)
|
||||||
|
.environmentObject(agentStatusChecker)
|
||||||
}
|
}
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
SetupView() { _ in
|
SetupView() { _ in
|
||||||
|
@ -3,10 +3,10 @@ import SecretKit
|
|||||||
import Brief
|
import Brief
|
||||||
|
|
||||||
struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentStatusCheckerProtocol>: View {
|
struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentStatusCheckerProtocol>: View {
|
||||||
|
|
||||||
@ObservedObject var storeList: SecretStoreList
|
@EnvironmentObject var storeList: SecretStoreList
|
||||||
@ObservedObject var updater: UpdaterType
|
@EnvironmentObject var updater: UpdaterType
|
||||||
@ObservedObject var agentStatusChecker: AgentStatusCheckerType
|
@EnvironmentObject var agentStatusChecker: AgentStatusCheckerType
|
||||||
var runSetupBlock: (() -> Void)?
|
var runSetupBlock: (() -> Void)?
|
||||||
|
|
||||||
@State private var active: AnySecret.ID?
|
@State private var active: AnySecret.ID?
|
||||||
@ -68,7 +68,7 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showingCreation) {
|
.sheet(isPresented: $showingCreation) {
|
||||||
CreateSecretView(store: storeList.modifiableStore!) {
|
CreateSecretView {
|
||||||
self.showingCreation = false
|
self.showingCreation = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,30 +154,30 @@ private enum Constants {
|
|||||||
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
#if DEBUG
|
//#if DEBUG
|
||||||
|
//
|
||||||
struct ContentView_Previews: PreviewProvider {
|
//struct ContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
// static var previews: some View {
|
||||||
Group {
|
// Group {
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)],
|
// ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)],
|
||||||
modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]),
|
// modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]),
|
||||||
updater: PreviewUpdater(),
|
// updater: PreviewUpdater(),
|
||||||
agentStatusChecker: PreviewAgentStatusChecker())
|
// agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
// ContentView(storeList: Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
||||||
agentStatusChecker: PreviewAgentStatusChecker())
|
// agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store()]), updater: PreviewUpdater(),
|
// ContentView(storeList: Preview.storeList(stores: [Preview.Store()]), updater: PreviewUpdater(),
|
||||||
agentStatusChecker: PreviewAgentStatusChecker())
|
// agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
ContentView(storeList: Preview.storeList(modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
// ContentView(storeList: Preview.storeList(modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
||||||
agentStatusChecker: PreviewAgentStatusChecker())
|
// agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .advisory),
|
// ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .advisory),
|
||||||
agentStatusChecker: PreviewAgentStatusChecker())
|
// agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
// ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
||||||
agentStatusChecker: PreviewAgentStatusChecker())
|
// agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
// ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
||||||
agentStatusChecker: PreviewAgentStatusChecker(running: false))
|
// agentStatusChecker: PreviewAgentStatusChecker(running: false))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
#endif
|
//#endif
|
||||||
|
@ -3,7 +3,7 @@ import SecretKit
|
|||||||
|
|
||||||
struct CreateSecretView: View {
|
struct CreateSecretView: View {
|
||||||
|
|
||||||
@ObservedObject var store: AnySecretStoreModifiable
|
@EnvironmentObject var store: AnySecretStoreModifiable
|
||||||
|
|
||||||
@State var name = ""
|
@State var name = ""
|
||||||
@State var requiresAuthentication = true
|
@State var requiresAuthentication = true
|
||||||
|
Loading…
Reference in New Issue
Block a user