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 {
|
2021-01-31 07:01:17 +00:00
|
|
|
|
2020-09-22 06:12:50 +00:00
|
|
|
@ObservedObject var store: StoreType
|
|
|
|
@Binding var showing: Bool
|
2021-01-31 07:01:17 +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 {
|
2021-12-15 05:03:42 +00:00
|
|
|
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:")
|
2020-11-11 23:32:28 +00:00
|
|
|
TextField("Shhhhh", text: $name).focusable()
|
2020-03-07 08:00:09 +00:00
|
|
|
}
|
|
|
|
HStack {
|
2021-01-31 07:01:17 +00:00
|
|
|
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
|
|
|
}
|
2021-01-31 07:01:17 +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
|
|
|
}
|
|
|
|
}
|