Files
Remote-Control-Center/mc_test/dist/renderer/assets/GuacamoleViewer-DQlYXUqt.js
2025-11-25 09:56:15 +03:00

2 lines
4.6 KiB
JavaScript
Executable File

import{r as n,l as c,j as e}from"./main-D-T5fPSb.js";function w({machine:t,connectionUrl:m,enableSftp:y,onError:l,onDisconnect:h}){const[p,d]=n.useState(!0),[k,x]=n.useState(null),[r,o]=n.useState(!1),s=n.useRef(null),f=n.useRef(null);return n.useEffect(()=>((async()=>{try{if(d(!0),x(null),c.info("guacamole-viewer","Initializing Guacamole session",{machineId:t.id,machineName:t.name,connectionUrl:m}),s.current)if(!s.current.src||s.current.src==="about:blank")c.debug("guacamole-viewer","Loading connection URL",{url:m}),s.current.src=m;else{c.debug("guacamole-viewer","iframe already loaded, keeping existing session"),d(!1);return}const a=()=>{d(!1),c.info("guacamole-viewer","Guacamole session loaded",{machineId:t.id}),setTimeout(()=>{s.current&&(s.current.focus(),o(!0))},500)},i=()=>{const u=new Error("Failed to load Guacamole session");x(u),d(!1),l==null||l(u)};if(s.current)return s.current.addEventListener("load",a),s.current.addEventListener("error",i),()=>{var u,b;(u=s.current)==null||u.removeEventListener("load",a),(b=s.current)==null||b.removeEventListener("error",i)}}catch(a){const i=a instanceof Error?a:new Error("Unknown error occurred");c.error("guacamole-viewer","Connection failed",{machineId:t.id,error:i.message}),x(i),l==null||l(i),d(!1)}})(),()=>{c.info("guacamole-viewer","Cleaning up connection",{machineId:t.id}),o(!1)}),[t.id]),n.useEffect(()=>{const g=a=>{f.current&&!f.current.contains(a.target)&&r&&(o(!1),s.current&&s.current.blur())};return document.addEventListener("mousedown",g),()=>{document.removeEventListener("mousedown",g)}},[r]),k?e.jsx("div",{className:"flex-1 flex items-center justify-center bg-red-50 text-red-600 p-4 rounded-kaspersky",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-medium mb-2",children:"Connection Error"}),e.jsx("p",{className:"text-sm mb-4",children:k.message}),e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsx("button",{onClick:()=>window.location.reload(),className:"px-4 py-2 bg-red-600 text-white rounded-kaspersky hover:bg-red-700 transition-colors",children:"Retry"}),e.jsx("button",{onClick:h,className:"px-4 py-2 bg-gray-600 text-white rounded-kaspersky hover:bg-gray-700 transition-colors",children:"Disconnect"})]})]})}):e.jsx("div",{className:"w-full h-full flex flex-col bg-kaspersky-bg",children:e.jsxs("div",{ref:f,className:`flex-1 relative bg-kaspersky-bg overflow-hidden ${r?"ring-2 ring-kaspersky-primary ring-opacity-50":""}`,children:[p&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-kaspersky-bg bg-opacity-75 z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-8 h-8 border-4 border-kaspersky-base border-t-transparent rounded-full animate-spin mx-auto"}),e.jsxs("p",{className:"mt-2 text-kaspersky-text",children:["Connecting to ",t.name,"..."]})]})}),!p&&!r&&e.jsx("div",{className:"absolute inset-0 z-10 cursor-pointer",onClick:()=>{s.current&&(s.current.focus(),o(!0))},title:"Click to activate console"}),!p&&e.jsx("div",{className:"absolute top-4 left-1/2 transform -translate-x-1/2 z-20 pointer-events-none select-none",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2 rounded-lg text-sm font-semibold transition-all duration-300 ${r?"bg-kaspersky-primary text-white shadow-kaspersky-lg":"bg-kaspersky-secondary bg-opacity-90 text-kaspersky-text-white"}`,children:[e.jsx("div",{className:`w-3 h-3 rounded-full transition-all duration-300 ${r?"bg-kaspersky-danger animate-pulse":"bg-kaspersky-text-lighter"}`}),e.jsx("span",{children:r?"Console Active":"Console Inactive"})]}),e.jsx("div",{className:"bg-kaspersky-secondary bg-opacity-75 backdrop-blur-sm text-kaspersky-text-white px-3 py-1.5 rounded-md text-xs font-medium",children:y?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"opacity-75",children:"Settings & SFTP:"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-kaspersky-base bg-opacity-50 rounded text-[10px] font-mono",children:"Ctrl+Shift+Alt"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"opacity-75",children:"Settings:"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-kaspersky-base bg-opacity-50 rounded text-[10px] font-mono",children:"Ctrl+Shift+Alt"})]})})]})}),e.jsx("iframe",{ref:s,className:"w-full h-full border-0",title:`Remote Desktop - ${t.name}`,allow:"clipboard-read; clipboard-write; keyboard-map *; pointer-lock",sandbox:"allow-same-origin allow-scripts allow-forms allow-popups allow-pointer-lock allow-modals allow-downloads",onFocus:()=>o(!0),onBlur:()=>o(!1)})]})})}export{w as default};