secretive/Secretive/SecretDetailView.swift

64 lines
2.1 KiB
Swift
Raw Normal View History

2020-03-04 07:14:38 +00:00
import SwiftUI
import SecretKit
struct SecretDetailView<SecretType: Secret>: View {
@State var secret: SecretType
let keyWriter = OpenSSHKeyWriter()
var body: some View {
Form {
Section {
GroupBox(label: Text("Fingerprint")) {
HStack {
Text(keyWriter.openSSHFingerprint(secret: secret))
Spacer()
}
.frame(minWidth: 150, maxWidth: .infinity)
.padding()
}.onDrag {
return NSItemProvider(item: NSData(data: self.keyWriter.openSSHFingerprint(secret: self.secret).data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
}
2020-03-06 06:53:04 +00:00
Spacer().frame(height: 10)
2020-03-04 07:14:38 +00:00
GroupBox(label: Text("Public Key")) {
2020-03-07 03:07:38 +00:00
VStack {
Text(keyWriter.openSSHString(secret: secret))
.multilineTextAlignment(.leading)
.frame(minWidth: 150, maxWidth: .infinity)
HStack {
Spacer()
Button(action: copy) {
Text("Copy")
}
}
}
.padding()
2020-03-04 07:14:38 +00:00
}
.onDrag {
return NSItemProvider(item: NSData(data: self.keyString.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
}
2020-03-06 06:53:04 +00:00
Spacer()
2020-03-04 07:14:38 +00:00
}
}.padding()
.frame(minHeight: 150, maxHeight: .infinity)
}
var keyString: String {
keyWriter.openSSHString(secret: secret)
}
func copy() {
NSPasteboard.general.declareTypes([.string], owner: nil)
NSPasteboard.general.setString(keyString, forType: .string)
}
}
2020-03-12 04:58:32 +00:00
struct SecretDetailView_Previews: PreviewProvider {
static var previews: some View {
SecretDetailView(secret: Preview.Store(numberOfRandomSecrets: 1).secrets[0])
}
}