Files
ShhShell/ShhShell/Views/Keys/KeyImporterView.swift
neon443 7b127127e7 solarium complete
idr most of ts
cleaned up stuff
remove glassbutton
2025-09-10 21:09:28 +01:00

80 lines
1.8 KiB
Swift

//
// KeyImporterView.swift
// ShhShell
//
// Created by neon443 on 01/07/2025.
//
import SwiftUI
struct KeyImporterView: View {
@ObservedObject var keyManager: KeyManager
@Environment(\.dismiss) var dismiss
@State var keyName: String = UIDevice().model + " at " + Date().formatted(date: .numeric, time: .omitted)
@State var privkeyStr: String = ""
@State var keyType: KeyType = .ed25519
var keypair: Keypair {
Keypair(type: keyType, name: keyName, privateKey: privkeyStr.data(using: .utf8) ?? Data())
}
var body: some View {
List {
TextBox(label: "Name", text: $keyName, prompt: "A name for your key")
HStack {
Text("Key Type")
Picker("Key type", selection: $keyType) {
ForEach(KeyType.allCases, id: \.self) { type in
Text(type.description)
.tag(type)
}
}
.pickerStyle(SegmentedPickerStyle())
}
Section {
HStack {
Text("Private Key")
Spacer()
Text("Required")
.foregroundStyle(.red)
}
.listRowSeparator(.hidden)
TextEditor(text: $privkeyStr)
.background(.gray.opacity(0.5))
.clipShape(RoundedRectangle(cornerRadius: 8))
.padding(.bottom, 5)
.padding(.horizontal, -8)
}
if !keypair.openSshPubkey.isEmpty {
Text(keypair.openSshPubkey.trimmingCharacters(in: .whitespacesAndNewlines))
.foregroundStyle(.gray)
}
}
.preferredColorScheme(.dark)
.overlay(alignment: .bottom) {
Button {
keyManager.importKey(type: keyType, priv: privkeyStr, name: keyName)
UINotificationFeedbackGenerator().notificationOccurred(.success)
dismiss()
} label: {
Text("Import")
.font(.title)
.bold()
}
.modifier(glassButton(prominent: true))
.padding(.bottom, 15)
}
}
}
#Preview {
KeyImporterView(keyManager: KeyManager())
}