may have actually fixed the whole hostkey changed flow, however accepting the new key causes the wierd keyboard issue when it opens the terminal

you can now forget hostkeys
removed the dispatchqueue on the disconnect function
updated updatehost to remove stupid ahh logic
This commit is contained in:
neon443
2025-08-05 11:14:00 +01:00
parent d6822f7614
commit ca34d3eafb
4 changed files with 23 additions and 15 deletions

View File

@@ -223,15 +223,16 @@ class HostsManager: ObservableObject, @unchecked Sendable {
} }
func updateHost(_ updatedHost: Host) { func updateHost(_ updatedHost: Host) {
let oldID = updatedHost.id // let oldID = updatedHost.id
if let index = hosts.firstIndex(where: { $0.id == updatedHost.id }) { if let index = hosts.firstIndex(where: { $0.id == updatedHost.id }) {
var updateHostWithNewID = updatedHost withAnimation { hosts[index] = updatedHost }
updateHostWithNewID.id = UUID() // var updateHostWithNewID = updatedHost
withAnimation { hosts[index] = updateHostWithNewID } // updateHostWithNewID.id = UUID()
// withAnimation { hosts[index] = updateHostWithNewID }
updateHostWithNewID.id = oldID //
withAnimation { hosts[index] = updateHostWithNewID } // updateHostWithNewID.id = oldID
// withAnimation { hosts[index] = updateHostWithNewID }
saveHosts() saveHosts()
} else { } else {
withAnimation { hosts.append(updatedHost) } withAnimation { hosts.append(updatedHost) }

View File

@@ -142,10 +142,9 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
} }
func disconnect() { func disconnect() {
DispatchQueue.main.async { self.hostkeyChanged = false
withAnimation { self.state = .idle } withAnimation { self.state = .idle }
withAnimation { self.testSuceeded = nil } withAnimation { self.testSuceeded = nil }
}
if let sessionID { if let sessionID {
Task { @MainActor in Task { @MainActor in

View File

@@ -112,8 +112,9 @@ struct ConnectionView: View {
.alert("Hostkey changed", isPresented: $handler.hostkeyChanged) { .alert("Hostkey changed", isPresented: $handler.hostkeyChanged) {
Button(role: .destructive) { Button(role: .destructive) {
handler.host.key = handler.getHostkey() handler.host.key = handler.getHostkey()
hostsManager.updateHost(handler.host) handler.disconnect()
handler.go() handler.go()
showTerminal = checkShell(handler.state)
} label: { } label: {
Text("Accept Hostkey") Text("Accept Hostkey")
} }
@@ -140,7 +141,6 @@ Hostkey fingerprint is \(handler.getHostkey() ?? "nil")
.toolbar { .toolbar {
ToolbarItem() { ToolbarItem() {
Button() { Button() {
hostsManager.updateHost(handler.host)
handler.go() handler.go()
showTerminal = checkShell(handler.state) showTerminal = checkShell(handler.state)
} label: { } label: {

View File

@@ -25,7 +25,7 @@ struct HostkeysView: View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text("Connect to some hosts to collect more hostkeys!") Text("Connect to some hosts to collect more hostkeys!")
.padding(.bottom) .padding(.bottom)
Text("ShhShell remembers hostkey fingerprints for you, and can alert you if they change.") Text("ShhShell remembers hostkey fingerprints for you, and will alert you if they change.")
.font(.subheadline) .font(.subheadline)
Text("This could be due a man in the middle attack, where a bad actor tries to impersonate your server.") Text("This could be due a man in the middle attack, where a bad actor tries to impersonate your server.")
.font(.subheadline) .font(.subheadline)
@@ -33,7 +33,7 @@ struct HostkeysView: View {
} }
} }
ForEach(hostsManager.hosts) { host in ForEach($hostsManager.hosts) { $host in
VStack(alignment: .leading) { VStack(alignment: .leading) {
if !host.name.isEmpty { if !host.name.isEmpty {
Text("name") Text("name")
@@ -49,6 +49,14 @@ struct HostkeysView: View {
.bold() .bold()
Text(host.key ?? "nil") Text(host.key ?? "nil")
} }
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(/*role: .destructive*/) {
host.key = nil
hostsManager.updateHost(host)
} label: {
Label("Forget", systemImage: "trash")
}
}
} }
} }
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)