// Browser (spec §10.3 «Apri il browser»; mockup 10 without the steps column): in Docker the remote view of the // server's browser and «Ho finito»; on Windows the browser is its own window. While Alberto uses the browser the // engine is still; «Ho finito» lets «Riprendi» become active after a verification. Leaving the page without «Ho finito» // (another page, a reload, closing the tab) gives the browser back, like closing the window on Windows: the server copies // the session if no view opens again within a moment (on Windows the window stays as it is until Alberto closes it). A browser at rest opens its start page; «?accesso=1» (the red strip of a disconnection) // opens the login page, once: the parameter leaves the address straight away. import { api } from '../core/api.js'; import { caps } from '../core/context.js'; import { h, icon, fill } from '../core/dom.js'; import { navigate, setQuery } from '../core/shell.js'; import { t } from '../core/text.js'; import { toast } from '../core/ui.js'; import { drivingLease, finishDriving, passwordNote, windowPanel } from './connection.js'; import { remoteView } from './remote-view.js'; export default { async mount(page) { page.title(t('browser.titolo')); const windows = caps().browserWindow; let status = null; try { status = await api('/api/connection', { signal: page.signal }); } catch { // the view says whether the browser answers } if (page.signal.aborted) return; const lease = drivingLease(page); const login = new URLSearchParams(location.search).get('accesso') === '1'; lease.begin(login); // Asked once: a reload of the page, or the tab restored later, must not open the login page again. if (login) setQuery({ accesso: null }); const message = h('div', { 'aria-live': 'polite' }); const done = async () => { const result = await finishDriving(); if (!result) return; // «Ho finito» gives the browser back on the server whatever the answer. lease.settled(); toast(result.message, result.connected ? '' : 'errore'); if (result.connected) navigate('/attivita'); else fill(message, h('div.avviso.rosso', icon('octagon-alert', 's'), h('span', result.message))); }; page.saveBar(h('div', { style: { display: 'contents' } }, h('span.nota', t('browser.aiuto')), h('div.destra', h('button.btn.primo.grande', { type: 'button', onclick: done }, t('impostazioni.collegamento.hoFinito'))))); fill(page.body, h('div.pagina-browser', message, windows ? windowPanel() : remoteView(page, { url: status && status.currentUrl, login: login || (status && status.state === 'notConnected') }).element, passwordNote(windows))); }, };