Files
bpq_gui/public/terminal-window.js
alberto c98c67e18b Add detached service windows and selectable terminal themes
Support standalone APRS, Monitor, Chat and Terminal views with courtesy screens, window focus and return controls, shared sessions and suspended embedded polling.

Add five persistent phosphor palettes, remove Console terminal idle disconnections, and display decoded Mic-E movement and altitude with expandable original packets.

Document the new behavior and add regression coverage. Validation: 182 tests passed; the known hanging PowerShell startup readiness test was excluded.
2026-10-19 22:15:15 +02:00

23 lines
1.6 KiB
JavaScript

// A detached view shares the authenticated browser session and its existing Telnet socket.
const $=selector=>document.querySelector(selector);
let station={features:{}},csrf='',page='terminal';
function navigate(){page='terminal';$('#terminal').hidden=false;}
function toast(text){$('#toast').textContent=text;$('#toast').hidden=false;clearTimeout(toast.timer);toast.timer=setTimeout(()=>$('#toast').hidden=true,6500);}
function terminalWindowError(text){document.dispatchEvent(new Event('bpq-detach-auth-lost'));csrf='';station={features:{}};$('#terminal').hidden=true;$('#terminal-window-error').hidden=false;$('#terminal-window-error-text').textContent=BPQI18n.t(text);}
async function api(url,options={}){
const {busy,...request}=options;
const response=await fetch('/api'+url,{...request,headers:{'Content-Type':'application/json',...(request.method==='POST'?{'X-CSRF-Token':csrf}:{}),...request.headers}});
const data=await response.json();
if(!response.ok){if(response.status===401)terminalWindowError('Sessione scaduta. Accedi nuovamente dal pannello.');throw new Error(data.error||'Richiesta fallita');}
return data;
}
$('#logout').onclick=async()=>{};
document.addEventListener('DOMContentLoaded',async()=>{
try{
const user=await api('/session');station=user.config;csrf=user.csrf;
if(!station.features.terminal){terminalWindowError('Terminale non configurato in BPQ.');return;}
document.title='BPQ Console · '+station.call+' · Terminal';
document.dispatchEvent(new Event('station-ready'));
}catch(error){if(csrf||!$('#terminal-window-error-text').textContent)terminalWindowError(error.message);}
});