mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-12-14 16:16:21 +00:00
Update AppImage
This commit is contained in:
@@ -41,80 +41,17 @@ export function ScriptTerminalModal({
|
|||||||
const [exitCode, setExitCode] = useState<number | null>(null)
|
const [exitCode, setExitCode] = useState<number | null>(null)
|
||||||
const [currentInteraction, setCurrentInteraction] = useState<WebInteraction | null>(null)
|
const [currentInteraction, setCurrentInteraction] = useState<WebInteraction | null>(null)
|
||||||
const [interactionInput, setInteractionInput] = useState("")
|
const [interactionInput, setInteractionInput] = useState("")
|
||||||
const wsRef = useRef<WebSocket | null>(null)
|
|
||||||
const terminalRef = useRef<any>(null)
|
const terminalRef = useRef<any>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return
|
if (!open) return
|
||||||
|
|
||||||
let ws: WebSocket | null = null
|
// We'll pass initMessage prop to TerminalPanel instead
|
||||||
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()
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (ws) {
|
// Cleanup if needed
|
||||||
ws.close()
|
|
||||||
wsRef.current = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [open, sessionId, scriptPath, params])
|
}, [open])
|
||||||
|
|
||||||
const getScriptWebSocketUrl = (): string => {
|
const getScriptWebSocketUrl = (): string => {
|
||||||
if (typeof window === "undefined") {
|
if (typeof window === "undefined") {
|
||||||
@@ -127,7 +64,7 @@ export function ScriptTerminalModal({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleInteractionResponse = (value: string) => {
|
const handleInteractionResponse = (value: string) => {
|
||||||
if (!wsRef.current || !currentInteraction) return
|
if (!terminalRef.current || !currentInteraction) return
|
||||||
|
|
||||||
const response = JSON.stringify({
|
const response = JSON.stringify({
|
||||||
type: "interaction_response",
|
type: "interaction_response",
|
||||||
@@ -136,7 +73,7 @@ export function ScriptTerminalModal({
|
|||||||
})
|
})
|
||||||
|
|
||||||
console.log("[v0] Sending interaction response:", response)
|
console.log("[v0] Sending interaction response:", response)
|
||||||
wsRef.current.send(response)
|
terminalRef.current.send(response)
|
||||||
setCurrentInteraction(null)
|
setCurrentInteraction(null)
|
||||||
setInteractionInput("")
|
setInteractionInput("")
|
||||||
}
|
}
|
||||||
@@ -170,7 +107,14 @@ export function ScriptTerminalModal({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 overflow-hidden">
|
<div className="flex-1 overflow-hidden">
|
||||||
<TerminalPanel ref={terminalRef} websocketUrl={getScriptWebSocketUrl()} />
|
<TerminalPanel
|
||||||
|
ref={terminalRef}
|
||||||
|
websocketUrl={getScriptWebSocketUrl()}
|
||||||
|
initMessage={{
|
||||||
|
script_path: scriptPath,
|
||||||
|
params: params,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Footer */}
|
{/* Footer */}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import type { CheatSheetResult } from "@/lib/cheat-sheet-result" // Declare Chea
|
|||||||
type TerminalPanelProps = {
|
type TerminalPanelProps = {
|
||||||
websocketUrl?: string
|
websocketUrl?: string
|
||||||
onClose?: () => void
|
onClose?: () => void
|
||||||
|
initMessage?: Record<string, any>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TerminalInstance {
|
interface TerminalInstance {
|
||||||
@@ -132,7 +133,7 @@ const proxmoxCommands = [
|
|||||||
{ cmd: "clear", desc: "Clear terminal screen" },
|
{ cmd: "clear", desc: "Clear terminal screen" },
|
||||||
]
|
]
|
||||||
|
|
||||||
export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onClose }) => {
|
export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onClose, initMessage }) => {
|
||||||
const [terminals, setTerminals] = useState<TerminalInstance[]>([])
|
const [terminals, setTerminals] = useState<TerminalInstance[]>([])
|
||||||
const [activeTerminalId, setActiveTerminalId] = useState<string>("")
|
const [activeTerminalId, setActiveTerminalId] = useState<string>("")
|
||||||
const [layout, setLayout] = useState<"single" | "grid">("grid")
|
const [layout, setLayout] = useState<"single" | "grid">("grid")
|
||||||
@@ -427,7 +428,14 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
|
|||||||
setTerminals((prev) =>
|
setTerminals((prev) =>
|
||||||
prev.map((t) => (t.id === terminal.id ? { ...t, isConnected: true, term, ws, fitAddon } : t)),
|
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()
|
syncSizeWithBackend()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user