2020-03-04 07:14:38 +00:00
|
|
|
import SwiftUI
|
|
|
|
import SecretKit
|
|
|
|
|
2020-09-22 06:12:50 +00:00
|
|
|
struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
2020-03-07 08:00:09 +00:00
|
|
|
|
2020-09-22 06:12:50 +00:00
|
|
|
@ObservedObject var store: StoreType
|
|
|
|
@Binding var showing: Bool
|
2020-03-07 08:00:09 +00:00
|
|
|
|
2020-09-22 06:12:50 +00:00
|
|
|
@State private var name = ""
|
|
|
|
@State private var requiresAuthentication = true
|
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
var body: some View {
|
2020-03-07 08:00:09 +00:00
|
|
|
VStack {
|
|
|
|
HStack {
|
|
|
|
Image(nsImage: NSApp.applicationIconImage)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 64, height: 64)
|
|
|
|
.padding()
|
|
|
|
VStack {
|
|
|
|
HStack {
|
|
|
|
Text("Create a New Secret").bold()
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
HStack {
|
|
|
|
Text("Name:")
|
2020-11-11 23:32:28 +00:00
|
|
|
TextField("Shhhhh", text: $name).focusable()
|
2020-03-07 08:00:09 +00:00
|
|
|
}
|
|
|
|
HStack {
|
|
|
|
Toggle(isOn: $requiresAuthentication) {
|
|
|
|
Text("Requires Authentication (Biometrics or Password)")
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-07 08:00:09 +00:00
|
|
|
HStack {
|
|
|
|
Spacer()
|
2020-09-22 06:12:50 +00:00
|
|
|
Button("Cancel") {
|
|
|
|
showing = false
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
2020-09-22 06:12:50 +00:00
|
|
|
.keyboardShortcut(.cancelAction)
|
|
|
|
Button("Create", action: save)
|
|
|
|
.disabled(name.isEmpty)
|
|
|
|
.keyboardShortcut(.defaultAction)
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
2020-03-07 08:00:09 +00:00
|
|
|
}.padding()
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
2020-03-07 08:00:09 +00:00
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
func save() {
|
|
|
|
try! store.create(name: name, requiresAuthentication: requiresAuthentication)
|
2020-09-22 06:12:50 +00:00
|
|
|
showing = false
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
|
|
|
}
|