40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
|
|
/* Kit host (v1) - window control for the desktop exe (WebView2 launcher) and the browser.
|
||
|
|
From _Tools\Library\web\kit.
|
||
|
|
|
||
|
|
Kit.host.exe true inside the launcher (Launcher.csproj); <html> gets class "exe"
|
||
|
|
Kit.host.fullscreen() exe: toggle borderless-maximised; browser: Fullscreen API
|
||
|
|
Kit.host.minimize() / Kit.host.quit() exe only (no-ops in the browser)
|
||
|
|
Kit.host.dragArea(el) mousedown on el itself drags the window, double-click = fullscreen
|
||
|
|
|
||
|
|
The launcher draws no title bar; put minimise/fullscreen/close buttons into the page and
|
||
|
|
show them only for html.exe (template: #winctl). */
|
||
|
|
(function (root) {
|
||
|
|
'use strict';
|
||
|
|
const Kit = (root.Kit = root.Kit || {});
|
||
|
|
const wv = root.chrome && root.chrome.webview;
|
||
|
|
const send = c => { if (wv) wv.postMessage(c); };
|
||
|
|
|
||
|
|
const host = {
|
||
|
|
exe: !!wv,
|
||
|
|
send,
|
||
|
|
fullscreen() {
|
||
|
|
if (wv) return send('maximize');
|
||
|
|
if (document.fullscreenElement) document.exitFullscreen().catch(() => {});
|
||
|
|
else document.documentElement.requestFullscreen().catch(() => {});
|
||
|
|
},
|
||
|
|
minimize: () => send('minimize'),
|
||
|
|
quit: () => send('quit'),
|
||
|
|
dragArea(el) {
|
||
|
|
if (!wv) return;
|
||
|
|
el.addEventListener('mousedown', e => { if (e.button === 0 && e.target === el) send('drag'); });
|
||
|
|
el.addEventListener('dblclick', e => { if (e.target === el) send('maximize'); });
|
||
|
|
},
|
||
|
|
};
|
||
|
|
Kit.host = host;
|
||
|
|
if (wv && typeof document !== 'undefined') document.documentElement.classList.add('exe');
|
||
|
|
// F11 in the browser: same toggle as the exe (the launcher handles F11 / Alt+Enter itself)
|
||
|
|
if (!wv && typeof addEventListener !== 'undefined') {
|
||
|
|
addEventListener('keydown', e => { if (e.key === 'F11') { e.preventDefault(); host.fullscreen(); } });
|
||
|
|
}
|
||
|
|
})(typeof window !== 'undefined' ? window : globalThis);
|