diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index bb182f5..bafecb0 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -223,15 +223,16 @@ class HostsManager: ObservableObject, @unchecked Sendable { } func updateHost(_ updatedHost: Host) { - let oldID = updatedHost.id +// let oldID = updatedHost.id if let index = hosts.firstIndex(where: { $0.id == updatedHost.id }) { - var updateHostWithNewID = updatedHost - updateHostWithNewID.id = UUID() - withAnimation { hosts[index] = updateHostWithNewID } - - updateHostWithNewID.id = oldID - withAnimation { hosts[index] = updateHostWithNewID } + withAnimation { hosts[index] = updatedHost } +// var updateHostWithNewID = updatedHost +// updateHostWithNewID.id = UUID() +// withAnimation { hosts[index] = updateHostWithNewID } +// +// updateHostWithNewID.id = oldID +// withAnimation { hosts[index] = updateHostWithNewID } saveHosts() } else { withAnimation { hosts.append(updatedHost) } diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index db3bd5b..d10b6fc 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -142,10 +142,9 @@ class SSHHandler: @unchecked Sendable, ObservableObject { } func disconnect() { - DispatchQueue.main.async { - withAnimation { self.state = .idle } - withAnimation { self.testSuceeded = nil } - } + self.hostkeyChanged = false + withAnimation { self.state = .idle } + withAnimation { self.testSuceeded = nil } if let sessionID { Task { @MainActor in diff --git a/ShhShell/Views/Hosts/ConnectionView.swift b/ShhShell/Views/Hosts/ConnectionView.swift index 1468d9d..52ed7fb 100644 --- a/ShhShell/Views/Hosts/ConnectionView.swift +++ b/ShhShell/Views/Hosts/ConnectionView.swift @@ -112,8 +112,9 @@ struct ConnectionView: View { .alert("Hostkey changed", isPresented: $handler.hostkeyChanged) { Button(role: .destructive) { handler.host.key = handler.getHostkey() - hostsManager.updateHost(handler.host) + handler.disconnect() handler.go() + showTerminal = checkShell(handler.state) } label: { Text("Accept Hostkey") } @@ -140,7 +141,6 @@ Hostkey fingerprint is \(handler.getHostkey() ?? "nil") .toolbar { ToolbarItem() { Button() { - hostsManager.updateHost(handler.host) handler.go() showTerminal = checkShell(handler.state) } label: { diff --git a/ShhShell/Views/Keys/HostkeysView.swift b/ShhShell/Views/Keys/HostkeysView.swift index b559ff0..6477de4 100644 --- a/ShhShell/Views/Keys/HostkeysView.swift +++ b/ShhShell/Views/Keys/HostkeysView.swift @@ -25,7 +25,7 @@ struct HostkeysView: View { VStack(alignment: .leading) { Text("Connect to some hosts to collect more hostkeys!") .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) Text("This could be due a man in the middle attack, where a bad actor tries to impersonate your server.") .font(.subheadline) @@ -33,7 +33,7 @@ struct HostkeysView: View { } } - ForEach(hostsManager.hosts) { host in + ForEach($hostsManager.hosts) { $host in VStack(alignment: .leading) { if !host.name.isEmpty { Text("name") @@ -49,6 +49,14 @@ struct HostkeysView: View { .bold() 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)