diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-10 13:06:18 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-10 13:06:18 +0100 |
| commit | ea5a277c6b8bb2ba48b0ca8822797cf6ab0b3405 (patch) | |
| tree | d2ce1c0fe156dcd9c53196c151bdfed091a25618 /static/app.js | |
| parent | 8ec2352c22780202fcd39982f1c3e65d2dae0cc1 (diff) | |
| download | deck-it-ea5a277c6b8bb2ba48b0ca8822797cf6ab0b3405.tar.gz deck-it-ea5a277c6b8bb2ba48b0ca8822797cf6ab0b3405.zip | |
feat: the PC tells the tablet it is going to sleep
deckit/sleep.py holds an elogind delay inhibitor and watches
PrepareForSleep with dbus-monitor. On a suspend the server marks its
answers with X-Deckit-Sleep for 2 s, so the tablet's next poll shows "The
PC is asleep" at once and drops its wake lock, then lets the inhibitor go.
On resume it takes the inhibitor again. The 15 s silence fallback stays,
worded "The PC is not answering", for a crash or a dropped tunnel.
The inhibitor's command is `tail --pid=<server>` and dbus-monitor has a
parent-death signal, so a killed server leaves no lock delaying every
suspend (checked with kill -9: both gone within 2 s).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static/app.js')
| -rw-r--r-- | static/app.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/static/app.js b/static/app.js index fb92352..3ec7dc2 100644 --- a/static/app.js +++ b/static/app.js @@ -228,6 +228,7 @@ function startPoll(name, panel, el) { const poll = async () => { try { const r = await fetch(`/api/${name}`); + if (r.headers.get("X-Deckit-Sleep")) return goodnight("The PC is asleep"); awake(); if (r.ok) panel.update?.(await r.json(), el); } catch { @@ -348,11 +349,17 @@ async function keepAwake() { } keepAwake(); -// A sleeping PC answers nothing: every poll fails or hangs. After 15 s -// without any answer the page says so and drops the wake lock, so the tablet -// sleeps too; the first answer takes both back. -// ponytail: a crashed server or a dropped tunnel reads as asleep as well. +// The server marks its answers for a moment before the PC suspends +// (deckit/sleep.py), so the page says "asleep" at once; a PC that stops +// answering without saying so (a crash, a dropped tunnel) gets the same +// overlay after 15 s. Either way the wake lock goes, so the tablet sleeps +// too, and the first plain answer takes both back. const ASLEEP_AFTER = 15000; +function goodnight(title) { + document.getElementById("asleep-title").textContent = title; + asleep.hidden = false; + wakeLock?.release(); +} let lastAnswer = Date.now(); function awake() { lastAnswer = Date.now(); @@ -362,10 +369,7 @@ function awake() { } } setInterval(() => { - if (asleep.hidden && Date.now() - lastAnswer > ASLEEP_AFTER) { - asleep.hidden = false; - wakeLock?.release(); - } + if (asleep.hidden && Date.now() - lastAnswer > ASLEEP_AFTER) goodnight("The PC is not answering"); }, 2000); document.addEventListener("visibilitychange", () => { |
