mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
toolbar in teminal view
animation in contentview withanimations in sshhandler
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
import Foundation
|
||||
import LibSSH
|
||||
import OSLog
|
||||
import SwiftUI
|
||||
|
||||
class SSHHandler: ObservableObject {
|
||||
private var session: ssh_session?
|
||||
@@ -55,7 +56,7 @@ class SSHHandler: ObservableObject {
|
||||
|
||||
session = ssh_new()
|
||||
guard session != nil else {
|
||||
connected = false
|
||||
withAnimation { connected = false }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -67,10 +68,10 @@ class SSHHandler: ObservableObject {
|
||||
if status != SSH_OK {
|
||||
logger.critical("connection not ok: \(status)")
|
||||
logSshGetError()
|
||||
connected = false
|
||||
withAnimation { connected = false }
|
||||
return
|
||||
}
|
||||
connected = true
|
||||
withAnimation { connected = true }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -82,18 +83,18 @@ class SSHHandler: ObservableObject {
|
||||
ssh_disconnect(session)
|
||||
ssh_free(session)
|
||||
session = nil
|
||||
authorized = false
|
||||
withAnimation { authorized = false }
|
||||
host.key = nil
|
||||
}
|
||||
|
||||
func testExec() {
|
||||
if ssh_is_connected(session) == 0 {
|
||||
testSuceeded = false
|
||||
withAnimation { testSuceeded = false }
|
||||
return
|
||||
}
|
||||
|
||||
guard authorized else {
|
||||
testSuceeded = false
|
||||
withAnimation { testSuceeded = false }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -103,7 +104,7 @@ class SSHHandler: ObservableObject {
|
||||
|
||||
let channel = ssh_channel_new(session)
|
||||
guard channel != nil else {
|
||||
testSuceeded = false
|
||||
withAnimation { testSuceeded = false }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -112,7 +113,7 @@ class SSHHandler: ObservableObject {
|
||||
ssh_channel_free(channel)
|
||||
logger.critical("session opening error")
|
||||
logSshGetError()
|
||||
testSuceeded = false
|
||||
withAnimation { testSuceeded = false }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -122,7 +123,7 @@ class SSHHandler: ObservableObject {
|
||||
ssh_channel_free(channel)
|
||||
logger.critical("session opening error")
|
||||
logSshGetError()
|
||||
testSuceeded = false
|
||||
withAnimation { testSuceeded = false }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ class SSHHandler: ObservableObject {
|
||||
ssh_channel_free(channel)
|
||||
logger.critical("write error")
|
||||
logSshGetError()
|
||||
testSuceeded = false
|
||||
withAnimation { testSuceeded = false }
|
||||
return
|
||||
}
|
||||
nbytes = ssh_channel_read(channel, &buffer, UInt32(MemoryLayout.size(ofValue: Character.self)), 0)
|
||||
@@ -150,7 +151,7 @@ class SSHHandler: ObservableObject {
|
||||
ssh_channel_free(channel)
|
||||
logger.critical("didnt read?")
|
||||
logSshGetError()
|
||||
testSuceeded = false
|
||||
withAnimation { testSuceeded = false }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ class SSHHandler: ObservableObject {
|
||||
ssh_channel_close(channel)
|
||||
ssh_channel_free(channel)
|
||||
print("testExec succeeded")
|
||||
testSuceeded = true
|
||||
withAnimation { testSuceeded = true }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ class SSHHandler: ObservableObject {
|
||||
logSshGetError()
|
||||
return false
|
||||
}
|
||||
authorized = true
|
||||
withAnimation { authorized = true }
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ class SSHHandler: ObservableObject {
|
||||
return false
|
||||
}
|
||||
print("auth success")
|
||||
authorized = true
|
||||
withAnimation { authorized = true }
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -245,7 +246,7 @@ class SSHHandler: ObservableObject {
|
||||
guard status == SSH_AUTH_SUCCESS.rawValue else { return false }
|
||||
|
||||
print("no security moment lol")
|
||||
authorized = true
|
||||
withAnimation { authorized = true }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ struct ContentView: View {
|
||||
}
|
||||
.disabled(!(handler.connected && handler.authorized))
|
||||
}
|
||||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,22 +10,28 @@ import Runestone
|
||||
|
||||
struct TerminalView: View {
|
||||
@ObservedObject var handler: SSHHandler
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Button("read from server") {
|
||||
handler.readFromChannel()
|
||||
}
|
||||
.fixedSize()
|
||||
Spacer()
|
||||
Button("disconnect") {
|
||||
handler.disconnect()
|
||||
withAnimation { handler.testSuceeded = false }
|
||||
withAnimation { handler.connected = false }
|
||||
}
|
||||
.disabled(!handler.connected)
|
||||
}
|
||||
TextViewController(text: $handler.terminal)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("reload") {
|
||||
handler.readFromChannel()
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button() {
|
||||
handler.disconnect()
|
||||
withAnimation { handler.testSuceeded = false }
|
||||
withAnimation { handler.connected = false }
|
||||
dismiss()
|
||||
} label: {
|
||||
Label("Exit", systemImage: "xmark.square.fill")
|
||||
}
|
||||
.disabled(!handler.connected)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user