From a6c121dc33694ff4358806ab8fa9aba2149c1159 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sat, 6 Dec 2025 12:46:41 +0100 Subject: [PATCH] Update AppImage --- AppImage/components/script-terminal-modal.tsx | 58 +++++-------------- AppImage/components/terminal-panel.tsx | 19 +++++- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/AppImage/components/script-terminal-modal.tsx b/AppImage/components/script-terminal-modal.tsx index d1d0244..5a31b5d 100644 --- a/AppImage/components/script-terminal-modal.tsx +++ b/AppImage/components/script-terminal-modal.tsx @@ -43,7 +43,6 @@ export function ScriptTerminalModal({ const [currentInteraction, setCurrentInteraction] = useState(null) const [interactionInput, setInteractionInput] = useState("") const terminalRef = useRef(null) - const wsRef = useRef(null) useEffect(() => { if (open) { @@ -53,43 +52,11 @@ export function ScriptTerminalModal({ params, sessionId, }) + setCurrentInteraction(null) + setInteractionInput("") } }, [open, scriptPath, scriptName, params, sessionId]) - useEffect(() => { - if (!open) return - - const handleWebSocketMessage = (event: MessageEvent) => { - try { - const data = JSON.parse(event.data) - console.log("[v0] Received WebSocket message:", data) - - if (data.type === "web_interaction") { - console.log("[v0] Detected web interaction:", data.interaction) - setCurrentInteraction(data.interaction) - } - } catch (e) { - // Not JSON, ignore (it's terminal output) - } - } - - const checkWs = setInterval(() => { - if (terminalRef.current?.ws) { - wsRef.current = terminalRef.current.ws - wsRef.current.addEventListener("message", handleWebSocketMessage) - clearInterval(checkWs) - console.log("[v0] Attached WebSocket message listener") - } - }, 100) - - return () => { - clearInterval(checkWs) - if (wsRef.current) { - wsRef.current.removeEventListener("message", handleWebSocketMessage) - } - } - }, [open]) - const getScriptWebSocketUrl = (): string => { if (typeof window === "undefined") { return `ws://localhost:${API_PORT}/ws/script/${sessionId}` @@ -101,14 +68,14 @@ export function ScriptTerminalModal({ } const wsUrl = getScriptWebSocketUrl() - console.log("[v0] ScriptTerminalModal WebSocket URL:", wsUrl) - console.log("[v0] ScriptTerminalModal initMessage:", { - script_path: scriptPath, - params: params, - }) + + const handleWebInteraction = (interaction: WebInteraction) => { + console.log("[v0] Received web interaction:", interaction) + setCurrentInteraction(interaction) + } const handleInteractionResponse = (value: string) => { - if (!wsRef.current || !currentInteraction) return + if (!terminalRef.current || !currentInteraction) return const response = JSON.stringify({ type: "interaction_response", @@ -117,7 +84,13 @@ export function ScriptTerminalModal({ }) console.log("[v0] Sending interaction response:", response) - wsRef.current.send(response) + + // Access the terminal instance to send the response + const terminal = terminalRef.current + if (terminal?.terminals?.[0]?.ws) { + terminal.terminals[0].ws.send(response) + } + setCurrentInteraction(null) setInteractionInput("") } @@ -158,6 +131,7 @@ export function ScriptTerminalModal({ script_path: scriptPath, params: params, }} + onWebInteraction={handleWebInteraction} /> diff --git a/AppImage/components/terminal-panel.tsx b/AppImage/components/terminal-panel.tsx index 57fe597..a0da963 100644 --- a/AppImage/components/terminal-panel.tsx +++ b/AppImage/components/terminal-panel.tsx @@ -27,6 +27,7 @@ type TerminalPanelProps = { websocketUrl?: string onClose?: () => void initMessage?: Record + onWebInteraction?: (interaction: any) => void } interface TerminalInstance { @@ -133,7 +134,12 @@ const proxmoxCommands = [ { cmd: "clear", desc: "Clear terminal screen" }, ] -export const TerminalPanel: React.FC = ({ websocketUrl, onClose, initMessage }) => { +export const TerminalPanel: React.FC = ({ + websocketUrl, + onClose, + initMessage, + onWebInteraction, +}) => { const [terminals, setTerminals] = useState([]) const [activeTerminalId, setActiveTerminalId] = useState("") const [layout, setLayout] = useState<"single" | "grid">("grid") @@ -440,6 +446,17 @@ export const TerminalPanel: React.FC = ({ websocketUrl, onCl } ws.onmessage = (event) => { + try { + const data = JSON.parse(event.data) + if (data.type === "web_interaction" && onWebInteraction) { + console.log("[v0] TerminalPanel: Intercepted web_interaction:", data.interaction) + onWebInteraction(data.interaction) + return // Don't write to terminal + } + } catch (e) { + // Not JSON, it's regular terminal output + } + term.write(event.data) }