diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-11 20:29:52 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-11 20:29:52 +0100 |
| commit | fea2e9b221a2d18f9c73e5763adf662128cea5ec (patch) | |
| tree | 018ac7111d3dce1e4768c7a702d4394baf5589e1 /static/app.js | |
| parent | c6f23856f080feee37c4972fb6689332b9873574 (diff) | |
| download | deck-it-fea2e9b221a2d18f9c73e5763adf662128cea5ec.tar.gz deck-it-fea2e9b221a2d18f9c73e5763adf662128cea5ec.zip | |
feat(tablet): dim the backlight after an idle timeout
After [tablet] dim_after seconds with no touch the page covers itself and
the tablet module's dim action lowers the backlight to dim_brightness over
adb, with auto brightness off meanwhile; an LCD's backlight is the drain,
so a dark page alone saves little. The touch on the cover only calls
undim, which restores both settings, as does the module's stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static/app.js')
| -rw-r--r-- | static/app.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/static/app.js b/static/app.js index 3e75a4b..b824667 100644 --- a/static/app.js +++ b/static/app.js @@ -270,6 +270,22 @@ setInterval(() => { if (asleep.hidden && Date.now() - lastAnswer > ASLEEP_AFTER) goodnight("The PC is not answering"); }, 2000); +// After [tablet] dim_after seconds with no touch the server lowers the +// tablet's backlight and a dark layer covers the page; the touch that lands +// on that layer only brings the brightness back. +const dimmer = document.getElementById("dimmer"); +let dimAfter = 0, dimTimer = null; +const tablet = (action) => fetch(`/api/tablet/${action}`, { + method: "POST", headers: { "Content-Type": "application/json" }, body: "{}", +}).catch(() => {}); +function touched() { + clearTimeout(dimTimer); + if (dimAfter > 0) dimTimer = setTimeout(() => { dimmer.hidden = false; tablet("dim"); }, dimAfter * 1000); +} +dimmer.addEventListener("click", () => { dimmer.hidden = true; tablet("undim"); }); +document.addEventListener("pointerdown", touched, true); +fetch("/api/tablet").then((r) => r.json()).then((t) => { dimAfter = t.dim_after ?? 0; touched(); }).catch(() => {}); + document.addEventListener("visibilitychange", () => { if (document.visibilityState === "visible") { lastAnswer = Math.max(lastAnswer, Date.now() - ASLEEP_AFTER + 5000); // a moment for the refresh below |
