fix symbol not updating on the fly but everything else does

added automatic string to data conversion for pubkey
renamed symbol to hostsymbol
reduce padding
This commit is contained in:
neon443
2025-06-26 10:31:15 +01:00
parent 5e0908206c
commit d213ce2c05
6 changed files with 34 additions and 32 deletions

View File

@@ -39,7 +39,7 @@
A9B15A9A2E0ABA0400F66E02 /* DialogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B15A992E0ABA0400F66E02 /* DialogView.swift */; }; A9B15A9A2E0ABA0400F66E02 /* DialogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B15A992E0ABA0400F66E02 /* DialogView.swift */; };
A9C4140C2E096DB7005E3047 /* SSHError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C4140B2E096DB7005E3047 /* SSHError.swift */; }; A9C4140C2E096DB7005E3047 /* SSHError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C4140B2E096DB7005E3047 /* SSHError.swift */; };
A9C897EF2DF1A9A400EF9A5F /* SSHHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C897EE2DF1A9A400EF9A5F /* SSHHandler.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 */; }; A9DA97732E0D40C100142DDC /* SymbolPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DA97722E0D40C100142DDC /* SymbolPreview.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@@ -112,7 +112,7 @@
A9B15A992E0ABA0400F66E02 /* DialogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialogView.swift; sourceTree = "<group>"; }; A9B15A992E0ABA0400F66E02 /* DialogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialogView.swift; sourceTree = "<group>"; };
A9C4140B2E096DB7005E3047 /* SSHError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHError.swift; sourceTree = "<group>"; }; A9C4140B2E096DB7005E3047 /* SSHError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHError.swift; sourceTree = "<group>"; };
A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHHandler.swift; sourceTree = "<group>"; }; A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHHandler.swift; sourceTree = "<group>"; };
A9DA97702E0D30ED00142DDC /* Symbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Symbol.swift; sourceTree = "<group>"; }; A9DA97702E0D30ED00142DDC /* HostSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostSymbol.swift; sourceTree = "<group>"; };
A9DA97722E0D40C100142DDC /* SymbolPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolPreview.swift; sourceTree = "<group>"; }; A9DA97722E0D40C100142DDC /* SymbolPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolPreview.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@@ -283,7 +283,7 @@
children = ( children = (
A93143BF2DF61B3200FCD5DB /* Host.swift */, A93143BF2DF61B3200FCD5DB /* Host.swift */,
A98554602E058433009051BD /* HostsManager.swift */, A98554602E058433009051BD /* HostsManager.swift */,
A9DA97702E0D30ED00142DDC /* Symbol.swift */, A9DA97702E0D30ED00142DDC /* HostSymbol.swift */,
A9DA97722E0D40C100142DDC /* SymbolPreview.swift */, A9DA97722E0D40C100142DDC /* SymbolPreview.swift */,
); );
path = Host; path = Host;
@@ -464,7 +464,7 @@
A9B15A9A2E0ABA0400F66E02 /* DialogView.swift in Sources */, A9B15A9A2E0ABA0400F66E02 /* DialogView.swift in Sources */,
A92538C92DEE0742007E0A18 /* ShhShellApp.swift in Sources */, A92538C92DEE0742007E0A18 /* ShhShellApp.swift in Sources */,
A96C6B002E0C45FE00F377FE /* KeyDetailView.swift in Sources */, A96C6B002E0C45FE00F377FE /* KeyDetailView.swift in Sources */,
A9DA97712E0D30ED00142DDC /* Symbol.swift in Sources */, A9DA97712E0D30ED00142DDC /* HostSymbol.swift in Sources */,
A98554612E058433009051BD /* HostsManager.swift in Sources */, A98554612E058433009051BD /* HostsManager.swift in Sources */,
A985545D2E055D4D009051BD /* ConnectionView.swift in Sources */, A985545D2E055D4D009051BD /* ConnectionView.swift in Sources */,
A98554592E0553AA009051BD /* KeyManager.swift in Sources */, A98554592E0553AA009051BD /* KeyManager.swift in Sources */,

View File

@@ -11,7 +11,7 @@ import SwiftUI
protocol HostPr: Codable, Identifiable, Equatable, Hashable { protocol HostPr: Codable, Identifiable, Equatable, Hashable {
var id: UUID { get set } var id: UUID { get set }
var name: String { get set } var name: String { get set }
var symbol: Symbol { get set } var symbol: HostSymbol { get set }
var label: String { get set } var label: String { get set }
var address: String { get set } var address: String { get set }
var port: Int { get set } var port: Int { get set }
@@ -26,7 +26,7 @@ protocol HostPr: Codable, Identifiable, Equatable, Hashable {
struct Host: HostPr { struct Host: HostPr {
var id = UUID() var id = UUID()
var name: String var name: String
var symbol: Symbol var symbol: HostSymbol
var label: String var label: String
var address: String var address: String
var port: Int var port: Int
@@ -39,7 +39,7 @@ struct Host: HostPr {
init( init(
name: String = "", name: String = "",
symbol: Symbol = .genericServer, symbol: HostSymbol = .genericServer,
label: String = "", label: String = "",
address: String, address: String,
port: Int = 22, port: Int = 22,

View File

@@ -8,7 +8,7 @@
import Foundation import Foundation
import SwiftUI import SwiftUI
enum Symbol: Codable, Hashable, Equatable, CaseIterable { enum HostSymbol: Codable, Equatable, Hashable, CaseIterable {
case desktopcomputer case desktopcomputer
case laptopcomputer case laptopcomputer

View File

@@ -37,7 +37,9 @@ class HostsManager: ObservableObject, @unchecked Sendable {
func updateHost(_ updatedHost: Host) { func updateHost(_ updatedHost: Host) {
if let index = savedHosts.firstIndex(where: { $0.id == updatedHost.id }) { 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() saveSavedHosts()
} }
} }

View File

@@ -8,7 +8,7 @@
import SwiftUI import SwiftUI
struct SymbolPreview: View { struct SymbolPreview: View {
@State var symbol: Symbol @State var symbol: HostSymbol
@State var label: String @State var label: String
var body: some View { var body: some View {
@@ -17,12 +17,10 @@ struct SymbolPreview: View {
Image(symbol.sf) Image(symbol.sf)
.resizable().scaledToFit() .resizable().scaledToFit()
.symbolRenderingMode(.monochrome) .symbolRenderingMode(.monochrome)
.padding(5)
} else { } else {
Image(systemName: symbol.sf) Image(systemName: symbol.sf)
.resizable().scaledToFit() .resizable().scaledToFit()
.symbolRenderingMode(.monochrome) .symbolRenderingMode(.monochrome)
.padding(5)
} }
Text(label) Text(label)
.font(.headline) .font(.headline)
@@ -32,5 +30,5 @@ struct SymbolPreview: View {
} }
#Preview { #Preview {
SymbolPreview(symbol: Symbol.desktopcomputer, label: "lo0") SymbolPreview(symbol: HostSymbol.desktopcomputer, label: "lo0")
} }

View File

@@ -27,7 +27,7 @@ struct ConnectionView: View {
Section { Section {
ScrollView(.horizontal) { ScrollView(.horizontal) {
HStack { HStack {
ForEach(Symbol.allCases, id: \.self) { symbol in ForEach(HostSymbol.allCases, id: \.self) { symbol in
ZStack { ZStack {
if handler.host.symbol == symbol { if handler.host.symbol == symbol {
RoundedRectangle(cornerRadius: 10) RoundedRectangle(cornerRadius: 10)
@@ -91,21 +91,26 @@ struct ConnectionView: View {
SecureField("Password", text: $handler.host.password) SecureField("Password", text: $handler.host.password)
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
HStack { TextField("", text: $pubkeyStr, prompt: Text("Public Key"))
TextField("", text: $pubkeyStr, prompt: Text("Public Key")) .onChange(of: pubkeyStr) { _ in
.onSubmit { let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "")
let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "") handler.host.publicKey = Data(newStr.utf8)
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)")) TextField("", text: $passphrase, prompt: Text("Passphrase (Optional)"))
} }
@@ -167,10 +172,7 @@ struct ConnectionView: View {
} }
} }
.onDisappear { .onDisappear {
guard hostsManager.getHostMatching(handler.host) == handler.host else { hostsManager.updateHost(handler.host)
hostsManager.updateHost(handler.host)
return
}
} }
.task { .task {
if let publicKeyData = handler.host.publicKey { if let publicKeyData = handler.host.publicKey {