From b4a9e9bb24ef98b8bcce1ddfc6da781b286f568a Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 16 Jun 2025 13:57:46 +0100 Subject: [PATCH] toolbar in teminal view animation in contentview withanimations in sshhandler --- ShhShell/SSH/SSHHandler.swift | 31 +++++++++++++++--------------- ShhShell/Views/ContentView.swift | 1 + ShhShell/Views/TerminalView.swift | 32 ++++++++++++++++++------------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index 5bb0ce3..b86aba3 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -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 } diff --git a/ShhShell/Views/ContentView.swift b/ShhShell/Views/ContentView.swift index 0d4de58..6d6b54b 100644 --- a/ShhShell/Views/ContentView.swift +++ b/ShhShell/Views/ContentView.swift @@ -77,6 +77,7 @@ struct ContentView: View { } .disabled(!(handler.connected && handler.authorized)) } + .transition(.opacity) } } } diff --git a/ShhShell/Views/TerminalView.swift b/ShhShell/Views/TerminalView.swift index db3cf38..7b0504c 100644 --- a/ShhShell/Views/TerminalView.swift +++ b/ShhShell/Views/TerminalView.swift @@ -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) + } + } } }