secretive/Sources/Secretive/Views/CreateSecretView.swift

58 lines
1.9 KiB
Swift
Raw Permalink Normal View History

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-09-22 06:12:50 +00:00
@ObservedObject var store: StoreType
@Binding var showing: Bool
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: NSApplication.shared.applicationIconImage)
2020-03-07 08:00:09 +00:00
.resizable()
.frame(width: 64, height: 64)
.padding()
VStack {
HStack {
Text("Create a New Secret").bold()
Spacer()
}
HStack {
Text("Name:")
TextField("Shhhhh", text: $name).focusable()
2020-03-07 08:00:09 +00:00
}
HStack {
VStack(spacing: 20) {
Picker("", selection: $requiresAuthentication) {
Text("Requires Authentication (Biometrics or Password) before each use").tag(true)
Text("Authentication not required when Mac is unlocked").tag(false)
}
.pickerStyle(RadioGroupPickerStyle())
2020-03-07 08:00:09 +00:00
}
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)
2022-06-08 05:02:49 +00:00
Button("Create", action: mainActorWrapped(save))
2020-09-22 06:12:50 +00:00
.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-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
}
}