From bb82c52747bea5bba713f8f5e021252c45f36fd8 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sat, 6 Dec 2025 11:30:49 +0100 Subject: [PATCH] Update AppImage --- AppImage/components/script-terminal-modal.tsx | 82 +++---------------- AppImage/components/terminal-panel.tsx | 12 ++- 2 files changed, 23 insertions(+), 71 deletions(-) diff --git a/AppImage/components/script-terminal-modal.tsx b/AppImage/components/script-terminal-modal.tsx index 80d8f5b..8e7817e 100644 --- a/AppImage/components/script-terminal-modal.tsx +++ b/AppImage/components/script-terminal-modal.tsx @@ -41,80 +41,17 @@ export function ScriptTerminalModal({ const [exitCode, setExitCode] = useState(null) const [currentInteraction, setCurrentInteraction] = useState(null) const [interactionInput, setInteractionInput] = useState("") - const wsRef = useRef(null) const terminalRef = useRef(null) useEffect(() => { if (!open) return - let ws: WebSocket | null = null - const wsUrl = getScriptWebSocketUrl() - - const connectWebSocket = () => { - try { - ws = new WebSocket(wsUrl) - wsRef.current = ws - - ws.onopen = () => { - console.log("[v0] WebSocket connected, sending init message") - const initMessage = JSON.stringify({ - script_path: scriptPath, - params: params, - }) - ws?.send(initMessage) - } - - ws.onmessage = (event) => { - try { - const data = JSON.parse(event.data) - - // Detectar interacciones híbridas - if (data.type === "interaction") { - console.log("[v0] Interaction detected:", data) - setCurrentInteraction(data as WebInteraction) - return - } - - // Detectar finalización - if (data.type === "exit") { - console.log("[v0] Script completed with exit code:", data.code) - setIsComplete(true) - setExitCode(data.code || 0) - return - } - - // Detectar errores - if (data.type === "error") { - console.error("[v0] Script error:", data.message) - return - } - } catch (e) { - // No es JSON, es output normal - TerminalPanel lo manejará - } - } - - ws.onerror = (error) => { - console.error("[v0] WebSocket error:", error) - } - - ws.onclose = () => { - console.log("[v0] WebSocket closed") - wsRef.current = null - } - } catch (error) { - console.error("[v0] Failed to create WebSocket:", error) - } - } - - connectWebSocket() + // We'll pass initMessage prop to TerminalPanel instead return () => { - if (ws) { - ws.close() - wsRef.current = null - } + // Cleanup if needed } - }, [open, sessionId, scriptPath, params]) + }, [open]) const getScriptWebSocketUrl = (): string => { if (typeof window === "undefined") { @@ -127,7 +64,7 @@ export function ScriptTerminalModal({ } const handleInteractionResponse = (value: string) => { - if (!wsRef.current || !currentInteraction) return + if (!terminalRef.current || !currentInteraction) return const response = JSON.stringify({ type: "interaction_response", @@ -136,7 +73,7 @@ export function ScriptTerminalModal({ }) console.log("[v0] Sending interaction response:", response) - wsRef.current.send(response) + terminalRef.current.send(response) setCurrentInteraction(null) setInteractionInput("") } @@ -170,7 +107,14 @@ export function ScriptTerminalModal({
- +
{/* Footer */} diff --git a/AppImage/components/terminal-panel.tsx b/AppImage/components/terminal-panel.tsx index d03ec7b..57fe597 100644 --- a/AppImage/components/terminal-panel.tsx +++ b/AppImage/components/terminal-panel.tsx @@ -26,6 +26,7 @@ import type { CheatSheetResult } from "@/lib/cheat-sheet-result" // Declare Chea type TerminalPanelProps = { websocketUrl?: string onClose?: () => void + initMessage?: Record } interface TerminalInstance { @@ -132,7 +133,7 @@ const proxmoxCommands = [ { cmd: "clear", desc: "Clear terminal screen" }, ] -export const TerminalPanel: React.FC = ({ websocketUrl, onClose }) => { +export const TerminalPanel: React.FC = ({ websocketUrl, onClose, initMessage }) => { const [terminals, setTerminals] = useState([]) const [activeTerminalId, setActiveTerminalId] = useState("") const [layout, setLayout] = useState<"single" | "grid">("grid") @@ -427,7 +428,14 @@ export const TerminalPanel: React.FC = ({ websocketUrl, onCl setTerminals((prev) => prev.map((t) => (t.id === terminal.id ? { ...t, isConnected: true, term, ws, fitAddon } : t)), ) - term.writeln("\x1b[32mConnected to ProxMenux terminal.\x1b[0m") + + if (initMessage) { + console.log("[v0] TerminalPanel: Sending init message:", initMessage) + ws.send(JSON.stringify(initMessage)) + } else { + term.writeln("\x1b[32mConnected to ProxMenux terminal.\x1b[0m") + } + syncSizeWithBackend() }