Update script-terminal-modal.tsx

This commit is contained in:
MacRimi
2025-12-10 19:44:39 +01:00
parent ecd3a4e490
commit b02a60f4b3

View File

@@ -359,6 +359,35 @@ export function ScriptTerminalModal({
} }
}, []) }, [])
useEffect(() => {
if (!isOpen) return
const handleVisibilityChange = () => {
if (document.hidden) {
// Enviar ping para mantener conexión activa cuando la pantalla se bloquea
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
wsRef.current.send(JSON.stringify({ type: "ping" }))
}
}
}
document.addEventListener("visibilitychange", handleVisibilityChange)
const keepAliveInterval = setInterval(() => {
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
wsRef.current.send(JSON.stringify({ type: "ping" }))
}
}, 30000)
return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange)
clearInterval(keepAliveInterval)
if (checkConnectionInterval.current) {
clearInterval(checkConnectionInterval.current)
}
}
}, [isOpen])
const getScriptWebSocketUrl = (sid: string): string => { const getScriptWebSocketUrl = (sid: string): string => {
if (typeof window === "undefined") { if (typeof window === "undefined") {
return `ws://localhost:${API_PORT}/ws/script/${sid}` return `ws://localhost:${API_PORT}/ws/script/${sid}`
@@ -509,6 +538,7 @@ export function ScriptTerminalModal({
style={{ height: isMobile || isTablet ? "80vh" : `${modalHeight}px`, maxHeight: "none" }} style={{ height: isMobile || isTablet ? "80vh" : `${modalHeight}px`, maxHeight: "none" }}
onInteractOutside={(e) => e.preventDefault()} onInteractOutside={(e) => e.preventDefault()}
onEscapeKeyDown={(e) => e.preventDefault()} onEscapeKeyDown={(e) => e.preventDefault()}
hideClose={true}
> >
<DialogTitle className="sr-only">{scriptTitle}</DialogTitle> <DialogTitle className="sr-only">{scriptTitle}</DialogTitle>
@@ -531,6 +561,21 @@ export function ScriptTerminalModal({
)} )}
</div> </div>
{(isTablet || (!isMobile && !isTablet)) && (
<div
className={`h-2 cursor-ns-resize flex items-center justify-center transition-all duration-150 ${
isResizing ? "bg-blue-500 h-3" : "bg-zinc-800 hover:bg-blue-500/50"
}`}
onMouseDown={handleResizeStart}
onTouchStart={handleResizeStart}
style={{ touchAction: "none" }}
>
<GripHorizontal
className={`h-4 w-4 transition-all duration-150 ${isResizing ? "text-white scale-110" : "text-zinc-500"}`}
/>
</div>
)}
{(isMobile || isTablet) && ( {(isMobile || isTablet) && (
<div className="flex flex-wrap gap-1.5 justify-center items-center px-1 bg-zinc-900 text-sm rounded-b-md border-t border-zinc-700 py-1.5"> <div className="flex flex-wrap gap-1.5 justify-center items-center px-1 bg-zinc-900 text-sm rounded-b-md border-t border-zinc-700 py-1.5">
<Button <Button
@@ -600,22 +645,7 @@ export function ScriptTerminalModal({
</div> </div>
)} )}
{(isTablet || (!isMobile && !isTablet)) && ( <div className="flex items-center justify-between gap-2 p-2 border-t bg-zinc-900">
<div
className={`h-2 cursor-ns-resize flex items-center justify-center transition-all duration-150 ${
isResizing ? "bg-blue-500 h-3" : "bg-zinc-800 hover:bg-blue-500/50"
}`}
onMouseDown={handleResizeStart}
onTouchStart={handleResizeStart}
style={{ touchAction: "none" }}
>
<GripHorizontal
className={`h-4 w-4 transition-all duration-150 ${isResizing ? "text-white scale-110" : "text-zinc-500"}`}
/>
</div>
)}
<div className="flex items-center justify-between p-4 border-t">
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<Activity className="h-5 w-5 text-blue-500" /> <Activity className="h-5 w-5 text-blue-500" />
<div <div