Use SettingsStore for querying the comment style in SecretDetailView

Fixes: https://github.com/maxgoedjen/secretive/pull/536#discussion_r1509655340
This commit is contained in:
Paul Heidekrüger 2024-04-05 10:30:48 +02:00
parent 5cbc4e5f88
commit e29dd20722

View File

@ -4,7 +4,7 @@ import SecretKit
struct SecretDetailView<SecretType: Secret>: View { struct SecretDetailView<SecretType: Secret>: View {
@State var secret: SecretType @State var secret: SecretType
@AppStorage("com.maxgoedjen.Secretive.commentStyle") var style: CommentStyle = .keyAndHost @EnvironmentObject private var settingsStore: SettingsStore
private let keyWriter = OpenSSHKeyWriter() private let keyWriter = OpenSSHKeyWriter()
private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: NSHomeDirectory().replacingOccurrences(of: Bundle.main.hostBundleID, with: Bundle.main.agentBundleID)) private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: NSHomeDirectory().replacingOccurrences(of: Bundle.main.hostBundleID, with: Bundle.main.agentBundleID))
@ -43,11 +43,12 @@ struct SecretDetailView<SecretType: Secret>: View {
} }
var keyString: String { var keyString: String {
var style: CommentStyle = CommentStyle(rawValue: settingsStore["com.maxgoedjen.Secretive.commentStyle"] ?? CommentStyle.keyAndHost.rawValue)!
switch style { switch style {
case CommentStyle.none: case .none:
keyWriter.openSSHString(secret: secret, comment: "") return keyWriter.openSSHString(secret: secret, comment: "")
default: case .keyAndHost:
keyWriter.openSSHString(secret: secret, comment: "\(dashedKeyName)@\(dashedHostName)") return keyWriter.openSSHString(secret: secret, comment: "\(dashedKeyName)@\(dashedHostName)")
} }
} }
} }