diff --git a/ShhShell.xcodeproj/project.pbxproj b/ShhShell.xcodeproj/project.pbxproj index 1357dd5..03dad6b 100644 --- a/ShhShell.xcodeproj/project.pbxproj +++ b/ShhShell.xcodeproj/project.pbxproj @@ -39,7 +39,7 @@ A9B15A9A2E0ABA0400F66E02 /* DialogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B15A992E0ABA0400F66E02 /* DialogView.swift */; }; A9C4140C2E096DB7005E3047 /* SSHError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C4140B2E096DB7005E3047 /* SSHError.swift */; }; A9C897EF2DF1A9A400EF9A5F /* SSHHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */; }; - A9DA97712E0D30ED00142DDC /* Symbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DA97702E0D30ED00142DDC /* Symbol.swift */; }; + A9DA97712E0D30ED00142DDC /* HostSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DA97702E0D30ED00142DDC /* HostSymbol.swift */; }; A9DA97732E0D40C100142DDC /* SymbolPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DA97722E0D40C100142DDC /* SymbolPreview.swift */; }; /* End PBXBuildFile section */ @@ -112,7 +112,7 @@ A9B15A992E0ABA0400F66E02 /* DialogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialogView.swift; sourceTree = ""; }; A9C4140B2E096DB7005E3047 /* SSHError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHError.swift; sourceTree = ""; }; A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHHandler.swift; sourceTree = ""; }; - A9DA97702E0D30ED00142DDC /* Symbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Symbol.swift; sourceTree = ""; }; + A9DA97702E0D30ED00142DDC /* HostSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostSymbol.swift; sourceTree = ""; }; A9DA97722E0D40C100142DDC /* SymbolPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolPreview.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -283,7 +283,7 @@ children = ( A93143BF2DF61B3200FCD5DB /* Host.swift */, A98554602E058433009051BD /* HostsManager.swift */, - A9DA97702E0D30ED00142DDC /* Symbol.swift */, + A9DA97702E0D30ED00142DDC /* HostSymbol.swift */, A9DA97722E0D40C100142DDC /* SymbolPreview.swift */, ); path = Host; @@ -464,7 +464,7 @@ A9B15A9A2E0ABA0400F66E02 /* DialogView.swift in Sources */, A92538C92DEE0742007E0A18 /* ShhShellApp.swift in Sources */, A96C6B002E0C45FE00F377FE /* KeyDetailView.swift in Sources */, - A9DA97712E0D30ED00142DDC /* Symbol.swift in Sources */, + A9DA97712E0D30ED00142DDC /* HostSymbol.swift in Sources */, A98554612E058433009051BD /* HostsManager.swift in Sources */, A985545D2E055D4D009051BD /* ConnectionView.swift in Sources */, A98554592E0553AA009051BD /* KeyManager.swift in Sources */, diff --git a/ShhShell/Host/Host.swift b/ShhShell/Host/Host.swift index 9cc88e4..ee8583a 100644 --- a/ShhShell/Host/Host.swift +++ b/ShhShell/Host/Host.swift @@ -11,7 +11,7 @@ import SwiftUI protocol HostPr: Codable, Identifiable, Equatable, Hashable { var id: UUID { get set } var name: String { get set } - var symbol: Symbol { get set } + var symbol: HostSymbol { get set } var label: String { get set } var address: String { get set } var port: Int { get set } @@ -26,7 +26,7 @@ protocol HostPr: Codable, Identifiable, Equatable, Hashable { struct Host: HostPr { var id = UUID() var name: String - var symbol: Symbol + var symbol: HostSymbol var label: String var address: String var port: Int @@ -39,7 +39,7 @@ struct Host: HostPr { init( name: String = "", - symbol: Symbol = .genericServer, + symbol: HostSymbol = .genericServer, label: String = "", address: String, port: Int = 22, diff --git a/ShhShell/Host/Symbol.swift b/ShhShell/Host/HostSymbol.swift similarity index 94% rename from ShhShell/Host/Symbol.swift rename to ShhShell/Host/HostSymbol.swift index fd12a5c..5573653 100644 --- a/ShhShell/Host/Symbol.swift +++ b/ShhShell/Host/HostSymbol.swift @@ -8,7 +8,7 @@ import Foundation import SwiftUI -enum Symbol: Codable, Hashable, Equatable, CaseIterable { +enum HostSymbol: Codable, Equatable, Hashable, CaseIterable { case desktopcomputer case laptopcomputer diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index ecb4fe4..7b763a0 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -37,7 +37,9 @@ class HostsManager: ObservableObject, @unchecked Sendable { func updateHost(_ updatedHost: Host) { if let index = savedHosts.firstIndex(where: { $0.id == updatedHost.id }) { - withAnimation { savedHosts[index] = updatedHost } + var updateHostWithNewID = updatedHost + updateHostWithNewID.id = UUID() + withAnimation { savedHosts[index] = updateHostWithNewID } saveSavedHosts() } } diff --git a/ShhShell/Host/SymbolPreview.swift b/ShhShell/Host/SymbolPreview.swift index f545a21..72209f7 100644 --- a/ShhShell/Host/SymbolPreview.swift +++ b/ShhShell/Host/SymbolPreview.swift @@ -8,7 +8,7 @@ import SwiftUI struct SymbolPreview: View { - @State var symbol: Symbol + @State var symbol: HostSymbol @State var label: String var body: some View { @@ -17,12 +17,10 @@ struct SymbolPreview: View { Image(symbol.sf) .resizable().scaledToFit() .symbolRenderingMode(.monochrome) - .padding(5) } else { Image(systemName: symbol.sf) .resizable().scaledToFit() .symbolRenderingMode(.monochrome) - .padding(5) } Text(label) .font(.headline) @@ -32,5 +30,5 @@ struct SymbolPreview: View { } #Preview { - SymbolPreview(symbol: Symbol.desktopcomputer, label: "lo0") + SymbolPreview(symbol: HostSymbol.desktopcomputer, label: "lo0") } diff --git a/ShhShell/Views/Hosts/ConnectionView.swift b/ShhShell/Views/Hosts/ConnectionView.swift index 62c5405..50b1c81 100644 --- a/ShhShell/Views/Hosts/ConnectionView.swift +++ b/ShhShell/Views/Hosts/ConnectionView.swift @@ -27,7 +27,7 @@ struct ConnectionView: View { Section { ScrollView(.horizontal) { HStack { - ForEach(Symbol.allCases, id: \.self) { symbol in + ForEach(HostSymbol.allCases, id: \.self) { symbol in ZStack { if handler.host.symbol == symbol { RoundedRectangle(cornerRadius: 10) @@ -91,21 +91,26 @@ struct ConnectionView: View { SecureField("Password", text: $handler.host.password) .textFieldStyle(.roundedBorder) - HStack { - TextField("", text: $pubkeyStr, prompt: Text("Public Key")) - .onSubmit { - let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "") - handler.host.publicKey = Data(newStr.utf8) - } - } + TextField("", text: $pubkeyStr, prompt: Text("Public Key")) + .onChange(of: pubkeyStr) { _ in + let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "") + handler.host.publicKey = Data(newStr.utf8) + } + .onSubmit { + let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "") + handler.host.publicKey = Data(newStr.utf8) + } + + SecureField("", text: $privkeyStr, prompt: Text("Private Key")) + .onSubmit { + let newStr = privkeyStr.replacingOccurrences(of: "\r\n", with: "") + handler.host.privateKey = Data(newStr.utf8) + } + .onChange(of: privkeyStr) { _ in + let newStr = privkeyStr.replacingOccurrences(of: "\r\n", with: "") + handler.host.privateKey = Data(newStr.utf8) + } - HStack { - SecureField("", text: $privkeyStr, prompt: Text("Private Key")) - .onSubmit { - let newStr = privkeyStr.replacingOccurrences(of: "\r\n", with: "") - handler.host.privateKey = Data(newStr.utf8) - } - } TextField("", text: $passphrase, prompt: Text("Passphrase (Optional)")) } @@ -167,10 +172,7 @@ struct ConnectionView: View { } } .onDisappear { - guard hostsManager.getHostMatching(handler.host) == handler.host else { - hostsManager.updateHost(handler.host) - return - } + hostsManager.updateHost(handler.host) } .task { if let publicKeyData = handler.host.publicKey {