UI update: has an x if failed testexec, withanimation cleanup
new hostkey variable
getHostKey returns Data
This commit is contained in:
neon443
2025-06-07 16:06:45 +01:00
parent 5e493c4865
commit 5199158e04
5 changed files with 43 additions and 19 deletions

View File

@@ -10,19 +10,28 @@ import SwiftUI
struct ContentView: View {
@ObservedObject var handler: SSHHandler
@State var connected: Bool = false
@State var testSucceded: Bool = false
@State var testSucceded: Bool?
var body: some View {
VStack {
Text(connected ? "connected" : "not connected")
.foregroundStyle(connected ? .green : .red)
Text(handler.authorized ? "authorized" : "unauthorized")
.foregroundStyle(handler.authorized ? .green : .red)
if testSucceded {
Image(systemName: "checkmark.circle")
if let testSucceded = testSucceded {
Image(systemName: testSucceded ? "checkmark.circle" : "xmark.circle")
.foregroundStyle(testSucceded ? .green : .red)
}
if handler.hostkey != nil {
Text("Hostkey: \(handler.hostkey!.base64EncodedString())")
}
TextField("address", text: $handler.address)
.textFieldStyle(.roundedBorder)
TextField(
"port",
text: Binding(
@@ -31,8 +40,10 @@ struct ContentView: View {
)
.keyboardType(.numberPad)
.textFieldStyle(.roundedBorder)
TextField("username", text: $handler.username)
.textFieldStyle(.roundedBorder)
TextField("password", text: $handler.password)
.textFieldStyle(.roundedBorder)
@@ -42,20 +53,28 @@ struct ContentView: View {
}
handler.authWithPw()
}
.disabled(connected)
Button("disconnect") {
handler.disconnect()
withAnimation { testSucceded = false }
withAnimation { connected = false}
withAnimation { connected = false }
withAnimation { testSucceded = nil }
}
.disabled(!connected)
Button("run a test command") {
withAnimation {
if handler.testExec() {
testSucceded = true
} else {
testSucceded = false
}
if handler.testExec() {
withAnimation { testSucceded = true }
} else {
withAnimation { testSucceded = false }
}
}
.disabled(!(connected && handler.authorized))
Button("request a shell") {
handler.openShell()
}
}
}
}