mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
enum Symbol: Codable, Hashable, Equatable, CaseIterable {
|
||||
enum HostSymbol: Codable, Equatable, Hashable, CaseIterable {
|
||||
case desktopcomputer
|
||||
case laptopcomputer
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user