added startup snippets - run a snippet on conect

This commit is contained in:
neon443
2025-08-08 13:55:58 +01:00
parent 693ef91fb8
commit bee12c8a39
4 changed files with 27 additions and 2 deletions

View File

@@ -32,6 +32,7 @@ struct Host: HostPr {
var password: String var password: String
var privateKeyID: UUID? var privateKeyID: UUID?
var key: String? var key: String?
var startupSnippetID: UUID?
var description: String { var description: String {
if name.isEmpty && address.isEmpty { if name.isEmpty && address.isEmpty {

View File

@@ -239,6 +239,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
func duplicateHost(_ hostToDup: Host) { func duplicateHost(_ hostToDup: Host) {
var hostNewID = hostToDup var hostNewID = hostToDup
hostNewID.id = UUID() hostNewID.id = UUID()
hostNewID.name.append(" copy")
if let index = hosts.firstIndex(where: { $0 == hostToDup }) { if let index = hosts.firstIndex(where: { $0 == hostToDup }) {
hosts.insert(hostNewID, at: index+1) hosts.insert(hostNewID, at: index+1)
Haptic.medium.trigger() Haptic.medium.trigger()

View File

@@ -75,8 +75,6 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
} catch { print("auth with none is not authed") } } catch { print("auth with none is not authed") }
guard state != .authorized else { return } guard state != .authorized else { return }
for method in getAuthMethods() { for method in getAuthMethods() {
guard state != .authorized else { break } guard state != .authorized else { break }
switch method { switch method {

View File

@@ -57,6 +57,28 @@ struct ConnectionView: View {
Text("None") Text("None")
.tag(nil as UUID?) .tag(nil as UUID?)
} }
.onAppear {
guard keyManager.keyIDs.contains(where: { $0 == handler.host.privateKeyID }) else {
handler.host.privateKeyID = nil
return
}
}
}
Section() {
Picker("Startup Snippet", selection: $handler.host.startupSnippetID) {
ForEach(hostsManager.snippets) { snip in
Text(snip.name).tag(snip.id as UUID?)
}
Divider()
Text("None").tag(nil as UUID?)
}
.onAppear {
guard hostsManager.snippets.contains(where: { $0.id == handler.host.startupSnippetID }) else {
handler.host.startupSnippetID = nil
return
}
}
} }
Button() { Button() {
@@ -130,6 +152,9 @@ Hostkey fingerprint is \(handler.getHostkey() ?? "nil")
Button() { Button() {
handler.go() handler.go()
showTerminal = checkShell(handler.state) showTerminal = checkShell(handler.state)
if showTerminal {
handler.writeToChannel(hostsManager.snippets.first(where: { $0.id == handler.host.startupSnippetID })?.content)
}
} label: { } label: {
Label( Label(
handler.connected ? "Disconnect" : "Connect", handler.connected ? "Disconnect" : "Connect",