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 */; };
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 = "<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>"; };
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>"; };
/* 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 */,

View File

@@ -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,

View File

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

View File

@@ -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()
}
}

View File

@@ -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")
}

View File

@@ -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 {