From 2abd859a290854e7b2a253b636eba2129a03d583 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Thu, 14 May 2026 08:09:27 -0400 Subject: [PATCH] feat(fusion_clock): NFC kiosk Wake Lock to keep screen on while active --- .../static/src/js/fusion_clock_nfc_kiosk.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fusion_clock/static/src/js/fusion_clock_nfc_kiosk.js b/fusion_clock/static/src/js/fusion_clock_nfc_kiosk.js index 2b7cda12..47794566 100644 --- a/fusion_clock/static/src/js/fusion_clock_nfc_kiosk.js +++ b/fusion_clock/static/src/js/fusion_clock_nfc_kiosk.js @@ -410,6 +410,43 @@ return canvasEl.toDataURL("image/jpeg", 0.7); } + // ────────────────────────────────────────────────────────────── + // Wake Lock — keeps the screen on while the kiosk page is active. + // Released automatically on tab close/navigation; re-acquired on + // visibilitychange when the page comes back to the foreground. + // ────────────────────────────────────────────────────────────── + let wakeLock = null; + + async function acquireWakeLock() { + if (!("wakeLock" in navigator)) { + debugLog("wakeLock: API not supported on this browser"); + return; + } + if (wakeLock) { + debugLog("wakeLock: already held, skipping"); + return; + } + try { + wakeLock = await navigator.wakeLock.request("screen"); + debugLog("wakeLock: acquired ✓ (screen will stay on)"); + wakeLock.addEventListener("release", () => { + debugLog("wakeLock: released by browser/OS"); + wakeLock = null; + }); + } catch (e) { + debugLog("wakeLock: request failed: " + (e && e.message)); + } + } + + document.addEventListener("visibilitychange", async () => { + if (document.visibilityState === "visible") { + debugLog("visibility: visible — re-acquiring wakeLock"); + await acquireWakeLock(); + } else { + debugLog("visibility: " + document.visibilityState); + } + }); + // ────────────────────────────────────────────────────────────── // Setup wizard activation // ────────────────────────────────────────────────────────────── @@ -428,6 +465,7 @@ if (photoRequired) throw camErr; console.warn("[nfc-kiosk] camera unavailable, continuing (photo not required)", camErr); } + await acquireWakeLock(); setState(STATE.IDLE); } catch (e) { stateContainer.innerHTML = `