diff --git a/ShhShell/Views/Terminal/DialogView.swift b/ShhShell/Views/Terminal/DialogView.swift index 752d51a..b19a958 100644 --- a/ShhShell/Views/Terminal/DialogView.swift +++ b/ShhShell/Views/Terminal/DialogView.swift @@ -9,7 +9,7 @@ import SwiftUI struct DialogView: View { @ObservedObject var handler: SSHHandler - @State var showDialog: Bool = true + @State var showDialog: Bool @State var icon: String = "network.slash" @State var headline: String = "Disconnected" @State var text: String = "Connection to the SSH server has been lost, try reconnecting" @@ -53,15 +53,12 @@ struct DialogView: View { .frame(maxWidth: .infinity, maxHeight: .infinity) } } - Button("show button") { - withAnimation { showDialog.toggle() } - } } } #Preview { ZStack { Color.black - DialogView(handler: SSHHandler(host: Host.debug)) + DialogView(handler: SSHHandler(host: Host.debug), showDialog: true) } } diff --git a/ShhShell/Views/Terminal/SSHTerminalView.swift b/ShhShell/Views/Terminal/SSHTerminalView.swift index b5d2c96..5713824 100644 --- a/ShhShell/Views/Terminal/SSHTerminalView.swift +++ b/ShhShell/Views/Terminal/SSHTerminalView.swift @@ -24,8 +24,8 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie super.init(frame: frame) terminalDelegate = self - sshQueue.async { - guard let handler = self.handler else { return } + sshQueue.async { [self] in + guard let handler = handler else { return } while handler.connected { if let read = handler.readFromChannel() { diff --git a/ShhShell/Views/Terminal/ShellView.swift b/ShhShell/Views/Terminal/ShellView.swift index b1a8707..b9fa435 100644 --- a/ShhShell/Views/Terminal/ShellView.swift +++ b/ShhShell/Views/Terminal/ShellView.swift @@ -9,6 +9,7 @@ import SwiftUI struct ShellView: View { @ObservedObject var handler: SSHHandler + @Environment(\.dismiss) var dismiss var body: some View { NavigationStack { @@ -22,6 +23,9 @@ struct ShellView: View { ToolbarItem { Button() { handler.go() + if !handler.connected { + dismiss() + } } label: { Label( handler.connected ? "Disconnect" : "Connect",