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 var channel: ssh_channel?
|
||||||
private let sshQueue = DispatchQueue(label: "SSH Queue")
|
private let sshQueue = DispatchQueue(label: "SSH Queue")
|
||||||
|
|
||||||
@Published var hostsManager = HostsManager()
|
// @Published var hostsManager = HostsManager()
|
||||||
|
|
||||||
@Published var connected: Bool = false
|
@Published var connected: Bool = false
|
||||||
@Published var authorized: Bool = false
|
@Published var authorized: Bool = false
|
||||||
@@ -27,7 +27,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
|||||||
|
|
||||||
private let userDefaults = NSUbiquitousKeyValueStore.default
|
private let userDefaults = NSUbiquitousKeyValueStore.default
|
||||||
private let logger = Logger(subsystem: "xy", category: "sshHandler")
|
private let logger = Logger(subsystem: "xy", category: "sshHandler")
|
||||||
|
|
||||||
init(
|
init(
|
||||||
host: Host
|
host: Host
|
||||||
// hostsManager: HostsManager
|
// hostsManager: HostsManager
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ import SwiftUI
|
|||||||
@main
|
@main
|
||||||
struct ShhShellApp: App {
|
struct ShhShellApp: App {
|
||||||
@StateObject var sshHandler: SSHHandler = SSHHandler(host: Host.blank)
|
@StateObject var sshHandler: SSHHandler = SSHHandler(host: Host.blank)
|
||||||
|
@StateObject var hostsManager: HostsManager = HostsManager()
|
||||||
@StateObject var keyManager: KeyManager = KeyManager()
|
@StateObject var keyManager: KeyManager = KeyManager()
|
||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView(
|
ContentView(
|
||||||
handler: sshHandler,
|
handler: sshHandler,
|
||||||
|
hostsManger: hostsManager,
|
||||||
keyManager: keyManager
|
keyManager: keyManager
|
||||||
)
|
)
|
||||||
.colorScheme(.dark)
|
.colorScheme(.dark)
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ConnectionView: View {
|
struct ConnectionView: View {
|
||||||
@StateObject var handler: SSHHandler
|
@ObservedObject var handler: SSHHandler
|
||||||
@StateObject var keyManager: KeyManager
|
@ObservedObject var hostsManager: HostsManager
|
||||||
|
@ObservedObject var keyManager: KeyManager
|
||||||
|
|
||||||
@State var passphrase: String = ""
|
@State var passphrase: String = ""
|
||||||
|
|
||||||
@@ -119,7 +120,7 @@ struct ConnectionView: View {
|
|||||||
if handler.host.key != nil {
|
if handler.host.key != nil {
|
||||||
Text("Hostkey: \(handler.host.key!.base64EncodedString())")
|
Text("Hostkey: \(handler.host.key!.base64EncodedString())")
|
||||||
.onChange(of: handler.host.key) { _ in
|
.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 {
|
guard handler.host.key == previousKnownHost.key else {
|
||||||
hostKeyChangedAlert = true
|
hostKeyChangedAlert = true
|
||||||
return
|
return
|
||||||
@@ -151,17 +152,17 @@ struct ConnectionView: View {
|
|||||||
}
|
}
|
||||||
.alert("Hostkey changed", isPresented: $hostKeyChangedAlert) {
|
.alert("Hostkey changed", isPresented: $hostKeyChangedAlert) {
|
||||||
Button("Accept New Hostkey", role: .destructive) {
|
Button("Accept New Hostkey", role: .destructive) {
|
||||||
handler.hostsManager.updateHost(handler.host)
|
hostsManager.updateHost(handler.host)
|
||||||
}
|
}
|
||||||
|
|
||||||
Button("Disconnect", role: .cancel) {
|
Button("Disconnect", role: .cancel) {
|
||||||
Task {
|
Task {
|
||||||
await handler.disconnect()
|
await handler.disconnect()
|
||||||
handler.host.key = handler.hostsManager.getHostMatching(handler.host)?.key
|
handler.host.key = hostsManager.getHostMatching(handler.host)?.key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} message: {
|
} 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)
|
.transition(.opacity)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
@@ -178,8 +179,8 @@ struct ConnectionView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
guard handler.hostsManager.getHostMatching(handler.host) == handler.host else {
|
guard hostsManager.getHostMatching(handler.host) == handler.host else {
|
||||||
handler.hostsManager.updateHost(handler.host)
|
hostsManager.updateHost(handler.host)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,6 +199,7 @@ struct ConnectionView: View {
|
|||||||
#Preview {
|
#Preview {
|
||||||
ConnectionView(
|
ConnectionView(
|
||||||
handler: SSHHandler(host: Host.debug),
|
handler: SSHHandler(host: Host.debug),
|
||||||
|
hostsManager: HostsManager(),
|
||||||
keyManager: KeyManager()
|
keyManager: KeyManager()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import SwiftUI
|
|||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@ObservedObject var handler: SSHHandler
|
@ObservedObject var handler: SSHHandler
|
||||||
|
@ObservedObject var hostsManger: HostsManager
|
||||||
@ObservedObject var keyManager: KeyManager
|
@ObservedObject var keyManager: KeyManager
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TabView {
|
TabView {
|
||||||
HostsView(
|
HostsView(
|
||||||
handler: handler,
|
handler: handler,
|
||||||
|
hostsManager: hostsManger,
|
||||||
keyManager: keyManager
|
keyManager: keyManager
|
||||||
)
|
)
|
||||||
.tabItem {
|
.tabItem {
|
||||||
@@ -31,6 +33,7 @@ struct ContentView: View {
|
|||||||
#Preview {
|
#Preview {
|
||||||
ContentView(
|
ContentView(
|
||||||
handler: SSHHandler(host: Host.debug),
|
handler: SSHHandler(host: Host.debug),
|
||||||
|
hostsManger: HostsManager(),
|
||||||
keyManager: KeyManager()
|
keyManager: KeyManager()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,25 +9,38 @@ import SwiftUI
|
|||||||
|
|
||||||
struct HostsView: View {
|
struct HostsView: View {
|
||||||
@ObservedObject var handler: SSHHandler
|
@ObservedObject var handler: SSHHandler
|
||||||
|
@ObservedObject var hostsManager: HostsManager
|
||||||
@ObservedObject var keyManager: KeyManager
|
@ObservedObject var keyManager: KeyManager
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
List {
|
List {
|
||||||
if handler.hostsManager.savedHosts.isEmpty {
|
if hostsManager.savedHosts.isEmpty {
|
||||||
Text("Add your first Host!")
|
Text("Add your first Host!")
|
||||||
Button() {
|
Button() {
|
||||||
withAnimation { handler.hostsManager.savedHosts.append(Host.blank) }
|
withAnimation { hostsManager.savedHosts.append(Host.blank) }
|
||||||
} label: {
|
} label: {
|
||||||
Text("Create")
|
Text("Create")
|
||||||
// .font()
|
|
||||||
}
|
}
|
||||||
.buttonStyle(.borderedProminent)
|
.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() {
|
NavigationLink() {
|
||||||
ConnectionView(
|
ConnectionView(
|
||||||
handler: SSHHandler(host: host),
|
handler: SSHHandler(host: host),
|
||||||
|
hostsManager: hostsManager,
|
||||||
keyManager: keyManager
|
keyManager: keyManager
|
||||||
)
|
)
|
||||||
} label: {
|
} label: {
|
||||||
@@ -40,9 +53,9 @@ struct HostsView: View {
|
|||||||
.animation(.default, value: host)
|
.animation(.default, value: host)
|
||||||
.swipeActions(edge: .trailing) {
|
.swipeActions(edge: .trailing) {
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
if let index = handler.hostsManager.savedHosts.firstIndex(where: { $0.id == host.id }) {
|
if let index = hostsManager.savedHosts.firstIndex(where: { $0.id == host.id }) {
|
||||||
let _ = withAnimation { handler.hostsManager.savedHosts.remove(at: index) }
|
let _ = withAnimation { hostsManager.savedHosts.remove(at: index) }
|
||||||
handler.hostsManager.saveSavedHosts()
|
hostsManager.saveSavedHosts()
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
Label("Delete", systemImage: "trash")
|
Label("Delete", systemImage: "trash")
|
||||||
@@ -57,10 +70,11 @@ struct HostsView: View {
|
|||||||
NavigationLink {
|
NavigationLink {
|
||||||
ConnectionView(
|
ConnectionView(
|
||||||
handler: SSHHandler(host: host),
|
handler: SSHHandler(host: host),
|
||||||
|
hostsManager: hostsManager,
|
||||||
keyManager: keyManager
|
keyManager: keyManager
|
||||||
)
|
)
|
||||||
.task(priority: .userInitiated) {
|
.onAppear {
|
||||||
withAnimation { handler.hostsManager.savedHosts.append(host) }
|
withAnimation { hostsManager.savedHosts.append(host) }
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
Label("Add", systemImage: "plus")
|
Label("Add", systemImage: "plus")
|
||||||
@@ -74,6 +88,7 @@ struct HostsView: View {
|
|||||||
#Preview {
|
#Preview {
|
||||||
HostsView(
|
HostsView(
|
||||||
handler: SSHHandler(host: Host.debug),
|
handler: SSHHandler(host: Host.debug),
|
||||||
|
hostsManager: HostsManager(),
|
||||||
keyManager: KeyManager()
|
keyManager: KeyManager()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user