aboutsummaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/app.js20
-rw-r--r--static/index.html4
2 files changed, 14 insertions, 10 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", () => {
diff --git a/static/index.html b/static/index.html
index d199a35..ca3e827 100644
--- a/static/index.html
+++ b/static/index.html
@@ -42,8 +42,8 @@
<div id="tab-body"></div>
<div id="asleep" hidden>
<div class="asleep-moon nf"></div>
- <div class="off-title">The PC is asleep</div>
- <div class="off-detail">The dashboard comes back when it wakes. Until then the tablet can sleep too.</div>
+ <div class="off-title" id="asleep-title"></div>
+ <div class="off-detail">The dashboard comes back when it answers again. Until then the tablet can sleep too.</div>
</div>
<script src="vendor/gridstack/gridstack-all.js"></script>
<script type="module" src="app.js"></script>