Files
ShhShell/ShhShell/Views/ContentView.swift
neon443 b4a9e9bb24 toolbar in teminal view
animation in contentview
withanimations in sshhandler
2025-06-16 13:57:46 +01:00

90 lines
2.3 KiB
Swift

//
// ContentView.swift
// ShhShell
//
// Created by neon443 on 02/06/2025.
//
import SwiftUI
struct ContentView: View {
@ObservedObject var handler: SSHHandler
// @State var connected: Bool = false
var body: some View {
NavigationStack {
List {
HStack {
Text(handler.connected ? "connected" : "not connected")
.modifier(foregroundColorStyle(handler.connected ? .green : .red))
Text(handler.authorized ? "authorized" : "unauthorized")
.modifier(foregroundColorStyle(handler.authorized ? .green : .red))
}
// if let testSucceded = testSucceded {
// Image(systemName: testSucceded ? "checkmark.circle" : "xmark.circle")
// .modifier(foregroundColorStyle(testSucceded ? .green : .red))
// }
if handler.host.key != nil {
Text("Hostkey: \(handler.host.key!.base64EncodedString())")
}
TextField("address", text: $handler.host.address)
.textFieldStyle(.roundedBorder)
TextField(
"port",
text: Binding(
get: { String(handler.host.port) },
set: { handler.host.port = Int($0) ?? 22} )
)
.keyboardType(.numberPad)
.textFieldStyle(.roundedBorder)
TextField("username", text: $handler.host.username)
.textFieldStyle(.roundedBorder)
TextField("password", text: $handler.host.password)
.textFieldStyle(.roundedBorder)
Button() {
handler.connect()
let _ = handler.authWithPw()
handler.openShell()
} label: {
Label("Connect", systemImage: "powerplug.portrait")
}
.disabled(handler.connected)
NavigationLink() {
TerminalView(handler: handler)
} label: {
Label("Open Terminal", systemImage: "apple.terminal")
}
.disabled(!(handler.connected && handler.authorized))
Button() {
withAnimation { handler.testExec() }
} label: {
if handler.testSuceeded {
Image(systemName: handler.testSuceeded ? "checkmark.circle" : "xmark.circle")
.modifier(foregroundColorStyle(handler.testSuceeded ? .green : .red))
} else {
Label("Test Connection", systemImage: "checkmark")
}
}
.disabled(!(handler.connected && handler.authorized))
}
.transition(.opacity)
}
}
}
#Preview {
ContentView(
handler: SSHHandler(host: debugHost())
)
}