From 65438286eceff672874f45b4427bb70a27c54703 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Mon, 1 Dec 2025 01:26:29 +0100 Subject: [PATCH] Update script-terminal-modal.tsx --- AppImage/components/script-terminal-modal.tsx | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/AppImage/components/script-terminal-modal.tsx b/AppImage/components/script-terminal-modal.tsx index bcd18a6..f607522 100644 --- a/AppImage/components/script-terminal-modal.tsx +++ b/AppImage/components/script-terminal-modal.tsx @@ -44,15 +44,24 @@ export function ScriptTerminalModal({ const [exitCode, setExitCode] = useState(null) const [currentInteraction, setCurrentInteraction] = useState(null) + const paramsStr = JSON.stringify(params) + useEffect(() => { if (!open) return + if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) { + console.log("[v0] WebSocket already connected, skipping initialization") + return + } + let term: any = null let fitAddon: any = null const initTerminal = async () => { if (!terminalRef.current) return + console.log("[v0] Initializing terminal for session:", sessionId) + // Dynamic import to avoid SSR issues const { Terminal } = await import("xterm") const { FitAddon } = await import("xterm-addon-fit") @@ -106,12 +115,14 @@ export function ScriptTerminalModal({ term.writeln("\x1b[32mConnected to script execution.\x1b[0m") console.log("[v0] WebSocket connected, sending init message") + const parsedParams = JSON.parse(paramsStr) + // Flask expects to receive the session info and will start the script ws.send( JSON.stringify({ script_path: scriptPath, script_name: scriptName, - params: params, + params: parsedParams, }), ) } @@ -181,14 +192,19 @@ export function ScriptTerminalModal({ initTerminal() return () => { - if (wsRef.current) { - wsRef.current.close() - } - if (termRef.current) { - termRef.current.dispose() + if (!open) { + console.log("[v0] Cleaning up WebSocket and terminal") + if (wsRef.current) { + wsRef.current.close() + wsRef.current = null + } + if (termRef.current) { + termRef.current.dispose() + termRef.current = null + } } } - }, [open, sessionId, scriptPath, scriptName, params]) + }, [open, sessionId, scriptPath, scriptName, paramsStr]) function getWebSocketUrl(): string { if (typeof window === "undefined") {