PlotDirector/PlotLine/wwwroot/js/application-display-mode.js
Nick Beckley e48889ac05 Complete desktop workspaces, context menus and plot health
Commit the pending application, help and browser regression work. Pin the patched PKCS dependency for the production release.
2026-10-31 09:27:04 +00:00

25 lines
1.3 KiB
JavaScript

/* Parser-blocking shell bootstrap: no DOM/body, layout, or network dependencies. */
(() => {
const root = document.documentElement;
const key = 'plotdirector.displayMode';
const media = window.matchMedia('(display-mode: standalone)');
let established = false;
try { established = sessionStorage.getItem(key) === 'standalone'; } catch { }
root.dataset.standalone = String(established);
let verified = false;
const verify = () => {
const current = media.matches || navigator.standalone === true;
const changed = !verified || current !== established;
established = current; verified = true;
root.dataset.standalone = String(established);
try { sessionStorage.setItem(key, established ? 'standalone' : 'browser'); } catch { }
if (changed) window.dispatchEvent(new CustomEvent('plotdirector:pwa-mode-changed', { detail: { standalone: established } }));
};
window.PlotDirectorPwa = Object.freeze({ get standalone() { return established; } });
// Verify synchronously before the body can paint, including first-ever launch.
// Session storage is window scoped: an installed window cannot poison a browser tab.
verify();
media.addEventListener('change', verify);
window.addEventListener('pageshow', verify);
})();