mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
moved hostsmanger back out because nested observedobjects are wierd
added multiView - it connects to all your hosts at once, this proves that i can do many at once --- for a future update
This commit is contained in:
@@ -15,7 +15,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
||||
private var channel: ssh_channel?
|
||||
private let sshQueue = DispatchQueue(label: "SSH Queue")
|
||||
|
||||
@Published var hostsManager = HostsManager()
|
||||
// @Published var hostsManager = HostsManager()
|
||||
|
||||
@Published var connected: Bool = false
|
||||
@Published var authorized: Bool = false
|
||||
|
||||
@@ -10,12 +10,14 @@ import SwiftUI
|
||||
@main
|
||||
struct ShhShellApp: App {
|
||||
@StateObject var sshHandler: SSHHandler = SSHHandler(host: Host.blank)
|
||||
@StateObject var hostsManager: HostsManager = HostsManager()
|
||||
@StateObject var keyManager: KeyManager = KeyManager()
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView(
|
||||
handler: sshHandler,
|
||||
hostsManger: hostsManager,
|
||||
keyManager: keyManager
|
||||
)
|
||||
.colorScheme(.dark)
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ConnectionView: View {
|
||||
@StateObject var handler: SSHHandler
|
||||
@StateObject var keyManager: KeyManager
|
||||
@ObservedObject var handler: SSHHandler
|
||||
@ObservedObject var hostsManager: HostsManager
|
||||
@ObservedObject var keyManager: KeyManager
|
||||
|
||||
@State var passphrase: String = ""
|
||||
|
||||
@@ -119,7 +120,7 @@ struct ConnectionView: View {
|
||||
if handler.host.key != nil {
|
||||
Text("Hostkey: \(handler.host.key!.base64EncodedString())")
|
||||
.onChange(of: handler.host.key) { _ in
|
||||
guard let previousKnownHost = handler.hostsManager.getHostMatching(handler.host) else { return }
|
||||
guard let previousKnownHost = hostsManager.getHostMatching(handler.host) else { return }
|
||||
guard handler.host.key == previousKnownHost.key else {
|
||||
hostKeyChangedAlert = true
|
||||
return
|
||||
@@ -151,17 +152,17 @@ struct ConnectionView: View {
|
||||
}
|
||||
.alert("Hostkey changed", isPresented: $hostKeyChangedAlert) {
|
||||
Button("Accept New Hostkey", role: .destructive) {
|
||||
handler.hostsManager.updateHost(handler.host)
|
||||
hostsManager.updateHost(handler.host)
|
||||
}
|
||||
|
||||
Button("Disconnect", role: .cancel) {
|
||||
Task {
|
||||
await handler.disconnect()
|
||||
handler.host.key = handler.hostsManager.getHostMatching(handler.host)?.key
|
||||
handler.host.key = hostsManager.getHostMatching(handler.host)?.key
|
||||
}
|
||||
}
|
||||
} message: {
|
||||
Text("Expected \(handler.hostsManager.getHostMatching(handler.host)?.key?.base64EncodedString() ?? "null")\nbut recieved \(handler.host.key?.base64EncodedString() ?? "null" ) from the server")
|
||||
Text("Expected \(hostsManager.getHostMatching(handler.host)?.key?.base64EncodedString() ?? "null")\nbut recieved \(handler.host.key?.base64EncodedString() ?? "null" ) from the server")
|
||||
}
|
||||
.transition(.opacity)
|
||||
.toolbar {
|
||||
@@ -178,8 +179,8 @@ struct ConnectionView: View {
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
guard handler.hostsManager.getHostMatching(handler.host) == handler.host else {
|
||||
handler.hostsManager.updateHost(handler.host)
|
||||
guard hostsManager.getHostMatching(handler.host) == handler.host else {
|
||||
hostsManager.updateHost(handler.host)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -198,6 +199,7 @@ struct ConnectionView: View {
|
||||
#Preview {
|
||||
ConnectionView(
|
||||
handler: SSHHandler(host: Host.debug),
|
||||
hostsManager: HostsManager(),
|
||||
keyManager: KeyManager()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@ObservedObject var handler: SSHHandler
|
||||
@ObservedObject var hostsManger: HostsManager
|
||||
@ObservedObject var keyManager: KeyManager
|
||||
|
||||
var body: some View {
|
||||
TabView {
|
||||
HostsView(
|
||||
handler: handler,
|
||||
hostsManager: hostsManger,
|
||||
keyManager: keyManager
|
||||
)
|
||||
.tabItem {
|
||||
@@ -31,6 +33,7 @@ struct ContentView: View {
|
||||
#Preview {
|
||||
ContentView(
|
||||
handler: SSHHandler(host: Host.debug),
|
||||
hostsManger: HostsManager(),
|
||||
keyManager: KeyManager()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,25 +9,38 @@ import SwiftUI
|
||||
|
||||
struct HostsView: View {
|
||||
@ObservedObject var handler: SSHHandler
|
||||
@ObservedObject var hostsManager: HostsManager
|
||||
@ObservedObject var keyManager: KeyManager
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
if handler.hostsManager.savedHosts.isEmpty {
|
||||
if hostsManager.savedHosts.isEmpty {
|
||||
Text("Add your first Host!")
|
||||
Button() {
|
||||
withAnimation { handler.hostsManager.savedHosts.append(Host.blank) }
|
||||
withAnimation { hostsManager.savedHosts.append(Host.blank) }
|
||||
} label: {
|
||||
Text("Create")
|
||||
// .font()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
ForEach(handler.hostsManager.savedHosts) { host in
|
||||
|
||||
//proves that u can connect to multiple at the same time
|
||||
// NavigationLink() {
|
||||
// ForEach(hostsManager.savedHosts) { host in
|
||||
// let miniHandler = SSHHandler(host: host)
|
||||
// TerminalController(handler: miniHandler)
|
||||
// .onAppear { miniHandler.go() }
|
||||
// }
|
||||
// } label: {
|
||||
// Label("multiview", systemImage: "square.split.2x2")
|
||||
// }
|
||||
|
||||
ForEach(hostsManager.savedHosts) { host in
|
||||
NavigationLink() {
|
||||
ConnectionView(
|
||||
handler: SSHHandler(host: host),
|
||||
hostsManager: hostsManager,
|
||||
keyManager: keyManager
|
||||
)
|
||||
} label: {
|
||||
@@ -40,9 +53,9 @@ struct HostsView: View {
|
||||
.animation(.default, value: host)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
if let index = handler.hostsManager.savedHosts.firstIndex(where: { $0.id == host.id }) {
|
||||
let _ = withAnimation { handler.hostsManager.savedHosts.remove(at: index) }
|
||||
handler.hostsManager.saveSavedHosts()
|
||||
if let index = hostsManager.savedHosts.firstIndex(where: { $0.id == host.id }) {
|
||||
let _ = withAnimation { hostsManager.savedHosts.remove(at: index) }
|
||||
hostsManager.saveSavedHosts()
|
||||
}
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
@@ -57,10 +70,11 @@ struct HostsView: View {
|
||||
NavigationLink {
|
||||
ConnectionView(
|
||||
handler: SSHHandler(host: host),
|
||||
hostsManager: hostsManager,
|
||||
keyManager: keyManager
|
||||
)
|
||||
.task(priority: .userInitiated) {
|
||||
withAnimation { handler.hostsManager.savedHosts.append(host) }
|
||||
.onAppear {
|
||||
withAnimation { hostsManager.savedHosts.append(host) }
|
||||
}
|
||||
} label: {
|
||||
Label("Add", systemImage: "plus")
|
||||
@@ -74,6 +88,7 @@ struct HostsView: View {
|
||||
#Preview {
|
||||
HostsView(
|
||||
handler: SSHHandler(host: Host.debug),
|
||||
hostsManager: HostsManager(),
|
||||
keyManager: KeyManager()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user