mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
added startup snippets - run a snippet on conect
This commit is contained in:
@@ -32,6 +32,7 @@ struct Host: HostPr {
|
||||
var password: String
|
||||
var privateKeyID: UUID?
|
||||
var key: String?
|
||||
var startupSnippetID: UUID?
|
||||
|
||||
var description: String {
|
||||
if name.isEmpty && address.isEmpty {
|
||||
|
||||
@@ -239,6 +239,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
func duplicateHost(_ hostToDup: Host) {
|
||||
var hostNewID = hostToDup
|
||||
hostNewID.id = UUID()
|
||||
hostNewID.name.append(" copy")
|
||||
if let index = hosts.firstIndex(where: { $0 == hostToDup }) {
|
||||
hosts.insert(hostNewID, at: index+1)
|
||||
Haptic.medium.trigger()
|
||||
|
||||
@@ -75,8 +75,6 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
||||
} catch { print("auth with none is not authed") }
|
||||
guard state != .authorized else { return }
|
||||
|
||||
|
||||
|
||||
for method in getAuthMethods() {
|
||||
guard state != .authorized else { break }
|
||||
switch method {
|
||||
|
||||
@@ -57,6 +57,28 @@ struct ConnectionView: View {
|
||||
Text("None")
|
||||
.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() {
|
||||
@@ -130,6 +152,9 @@ Hostkey fingerprint is \(handler.getHostkey() ?? "nil")
|
||||
Button() {
|
||||
handler.go()
|
||||
showTerminal = checkShell(handler.state)
|
||||
if showTerminal {
|
||||
handler.writeToChannel(hostsManager.snippets.first(where: { $0.id == handler.host.startupSnippetID })?.content)
|
||||
}
|
||||
} label: {
|
||||
Label(
|
||||
handler.connected ? "Disconnect" : "Connect",
|
||||
|
||||
Reference in New Issue
Block a user