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