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 Foundation
|
||||||
import LibSSH
|
import LibSSH
|
||||||
import OSLog
|
import OSLog
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
class SSHHandler: ObservableObject {
|
class SSHHandler: ObservableObject {
|
||||||
private var session: ssh_session?
|
private var session: ssh_session?
|
||||||
@@ -55,7 +56,7 @@ class SSHHandler: ObservableObject {
|
|||||||
|
|
||||||
session = ssh_new()
|
session = ssh_new()
|
||||||
guard session != nil else {
|
guard session != nil else {
|
||||||
connected = false
|
withAnimation { connected = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +68,10 @@ class SSHHandler: ObservableObject {
|
|||||||
if status != SSH_OK {
|
if status != SSH_OK {
|
||||||
logger.critical("connection not ok: \(status)")
|
logger.critical("connection not ok: \(status)")
|
||||||
logSshGetError()
|
logSshGetError()
|
||||||
connected = false
|
withAnimation { connected = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
connected = true
|
withAnimation { connected = true }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,18 +83,18 @@ class SSHHandler: ObservableObject {
|
|||||||
ssh_disconnect(session)
|
ssh_disconnect(session)
|
||||||
ssh_free(session)
|
ssh_free(session)
|
||||||
session = nil
|
session = nil
|
||||||
authorized = false
|
withAnimation { authorized = false }
|
||||||
host.key = nil
|
host.key = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExec() {
|
func testExec() {
|
||||||
if ssh_is_connected(session) == 0 {
|
if ssh_is_connected(session) == 0 {
|
||||||
testSuceeded = false
|
withAnimation { testSuceeded = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard authorized else {
|
guard authorized else {
|
||||||
testSuceeded = false
|
withAnimation { testSuceeded = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +104,7 @@ class SSHHandler: ObservableObject {
|
|||||||
|
|
||||||
let channel = ssh_channel_new(session)
|
let channel = ssh_channel_new(session)
|
||||||
guard channel != nil else {
|
guard channel != nil else {
|
||||||
testSuceeded = false
|
withAnimation { testSuceeded = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +113,7 @@ class SSHHandler: ObservableObject {
|
|||||||
ssh_channel_free(channel)
|
ssh_channel_free(channel)
|
||||||
logger.critical("session opening error")
|
logger.critical("session opening error")
|
||||||
logSshGetError()
|
logSshGetError()
|
||||||
testSuceeded = false
|
withAnimation { testSuceeded = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ class SSHHandler: ObservableObject {
|
|||||||
ssh_channel_free(channel)
|
ssh_channel_free(channel)
|
||||||
logger.critical("session opening error")
|
logger.critical("session opening error")
|
||||||
logSshGetError()
|
logSshGetError()
|
||||||
testSuceeded = false
|
withAnimation { testSuceeded = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +140,7 @@ class SSHHandler: ObservableObject {
|
|||||||
ssh_channel_free(channel)
|
ssh_channel_free(channel)
|
||||||
logger.critical("write error")
|
logger.critical("write error")
|
||||||
logSshGetError()
|
logSshGetError()
|
||||||
testSuceeded = false
|
withAnimation { testSuceeded = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nbytes = ssh_channel_read(channel, &buffer, UInt32(MemoryLayout.size(ofValue: Character.self)), 0)
|
nbytes = ssh_channel_read(channel, &buffer, UInt32(MemoryLayout.size(ofValue: Character.self)), 0)
|
||||||
@@ -150,7 +151,7 @@ class SSHHandler: ObservableObject {
|
|||||||
ssh_channel_free(channel)
|
ssh_channel_free(channel)
|
||||||
logger.critical("didnt read?")
|
logger.critical("didnt read?")
|
||||||
logSshGetError()
|
logSshGetError()
|
||||||
testSuceeded = false
|
withAnimation { testSuceeded = false }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +159,7 @@ class SSHHandler: ObservableObject {
|
|||||||
ssh_channel_close(channel)
|
ssh_channel_close(channel)
|
||||||
ssh_channel_free(channel)
|
ssh_channel_free(channel)
|
||||||
print("testExec succeeded")
|
print("testExec succeeded")
|
||||||
testSuceeded = true
|
withAnimation { testSuceeded = true }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +171,7 @@ class SSHHandler: ObservableObject {
|
|||||||
logSshGetError()
|
logSshGetError()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
authorized = true
|
withAnimation { authorized = true }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +184,7 @@ class SSHHandler: ObservableObject {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
print("auth success")
|
print("auth success")
|
||||||
authorized = true
|
withAnimation { authorized = true }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +246,7 @@ class SSHHandler: ObservableObject {
|
|||||||
guard status == SSH_AUTH_SUCCESS.rawValue else { return false }
|
guard status == SSH_AUTH_SUCCESS.rawValue else { return false }
|
||||||
|
|
||||||
print("no security moment lol")
|
print("no security moment lol")
|
||||||
authorized = true
|
withAnimation { authorized = true }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
.disabled(!(handler.connected && handler.authorized))
|
.disabled(!(handler.connected && handler.authorized))
|
||||||
}
|
}
|
||||||
|
.transition(.opacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,22 +10,28 @@ import Runestone
|
|||||||
|
|
||||||
struct TerminalView: View {
|
struct TerminalView: View {
|
||||||
@ObservedObject var handler: SSHHandler
|
@ObservedObject var handler: SSHHandler
|
||||||
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
var body: some View {
|
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)
|
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