mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-10 17:47:19 +00:00
Added comment option when generating key
This commit is contained in:
parent
3eaf155071
commit
e6e2902922
@ -5,9 +5,10 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
|
||||
@ObservedObject var store: StoreType
|
||||
@Binding var showing: Bool
|
||||
|
||||
@State private var comment = ""
|
||||
@State private var name = ""
|
||||
@State private var requiresAuthentication = true
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@ -25,6 +26,10 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
Text("Name:")
|
||||
TextField("Shhhhh", text: $name).focusable()
|
||||
}
|
||||
HStack {
|
||||
Text("Comment:")
|
||||
TextField("\(dashedUserName)@\(dashedHostName)", text: $comment).focusable()
|
||||
}
|
||||
HStack {
|
||||
Toggle(isOn: $requiresAuthentication) {
|
||||
Text("Requires Authentication (Biometrics or Password)")
|
||||
@ -45,9 +50,22 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
}.padding()
|
||||
}
|
||||
var dashedUserName: String {
|
||||
NSUserName().replacingOccurrences(of: " ", with: "-")
|
||||
}
|
||||
var dashedHostName: String {
|
||||
[Host.current().localizedName, "local"]
|
||||
.compactMap { $0 }
|
||||
.joined(separator: ".")
|
||||
.replacingOccurrences(of: " ", with: "-")
|
||||
}
|
||||
|
||||
func save() {
|
||||
try! store.create(name: name, requiresAuthentication: requiresAuthentication)
|
||||
if comment != "" {
|
||||
defaults.set(comment, forKey: name)
|
||||
}
|
||||
defaults.set(comment, forKey: name)
|
||||
showing = false
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ struct SecretDetailView<SecretType: Secret>: View {
|
||||
|
||||
@State var secret: SecretType
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
private let keyWriter = OpenSSHKeyWriter()
|
||||
|
||||
var body: some View {
|
||||
@ -33,7 +35,11 @@ struct SecretDetailView<SecretType: Secret>: View {
|
||||
}
|
||||
|
||||
var keyString: String {
|
||||
keyWriter.openSSHString(secret: secret, comment: "\(dashedUserName)@\(dashedHostName)")
|
||||
if defaults.string(forKey: secret.name) != "" {
|
||||
return keyWriter.openSSHString(secret: secret, comment: defaults.string(forKey: secret.name))
|
||||
} else {
|
||||
return keyWriter.openSSHString(secret: secret, comment: "\(dashedUserName)@\(dashedHostName)")
|
||||
}
|
||||
}
|
||||
|
||||
func copy() {
|
||||
|
Loading…
Reference in New Issue
Block a user