fix crash when disconnecting, fix close terminal on exit

This commit is contained in:
neon443
2025-06-26 12:49:27 +01:00
parent 319373682c
commit 51459f1839
2 changed files with 6 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
@Published var title: String = ""
@Published var state: SSHState = .idle
var connected: Bool {
return checkConnected(state)
return ssh_channel_is_open(channel) == 1 && checkConnected(state)
}
@Published var testSuceeded: Bool? = nil
@@ -46,7 +46,6 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
func go() {
guard !connected else {
withAnimation { state = .idle }
disconnect()
return
}

View File

@@ -28,19 +28,16 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie
sshQueue.async {
Task {
guard let handler = await self.handler else { return }
while handler.connected {
if let read = handler.readFromChannel() {
// Task { [weak self] in
// guard let self else { return }
Task { @MainActor in
self.feed(text: read)
}
// }
} else {
try? await Task.sleep(nanoseconds: 10_000_000) //10ms
Task {try? await Task.sleep(nanoseconds: 10_000_000) } //10ms
}
}
handler.disconnect()
}
}
}