addedfunctions to check state

large code cleanup thanks to this
This commit is contained in:
neon443
2025-06-25 12:40:16 +01:00
parent 66547dc58e
commit 46ba88aacb
3 changed files with 23 additions and 11 deletions

View File

@@ -20,8 +20,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
@Published var title: String = ""
@Published var state: SSHState = .idle
var connected: Bool {
return !(state == .idle || state == .connecting)
// return state == .authorized || state == .shellOpen || state == .authorizing
return checkConnected(state)
}
// @Published var connected: Bool = false
// @Published var authorized: Bool = false
@@ -57,6 +56,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
func go() {
guard !connected else {
withAnimation { state = .idle }
Task {
await disconnect()
}
@@ -130,8 +130,6 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
func disconnect() async {
await MainActor.run {
withAnimation { state = .idle }
// withAnimation { connected = false }
// withAnimation { authorized = false }
withAnimation { testSuceeded = nil }
}
@@ -171,7 +169,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
}
}
if state == .authorized {} else {
if !checkAuth(state) {
go()
}
@@ -180,7 +178,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
return
}
guard state == .authorized else {
guard checkAuth(state) else {
withAnimation { testSuceeded = false }
return
}
@@ -378,7 +376,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
status = ssh_channel_request_shell(self.channel)
guard status == SSH_OK else { return }
withAnimation { state = .shellOpen }
}
func readFromChannel() -> String? {

View File

@@ -14,3 +14,15 @@ enum SSHState {
case authorized
case shellOpen
}
func checkConnected(_ state: SSHState) -> Bool {
return !(state == .idle || state == .connecting)
}
func checkAuth(_ state: SSHState) -> Bool {
return state == .authorized || state == .shellOpen
}
func checkShell(_ state: SSHState) -> Bool {
return state == .shellOpen
}