aboutsummaryrefslogtreecommitdiffstats
path: root/deckit/server.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-10 13:06:18 +0100
committerDanilo M. <danix@danix.xyz>2026-11-10 13:06:18 +0100
commitea5a277c6b8bb2ba48b0ca8822797cf6ab0b3405 (patch)
treed2ce1c0fe156dcd9c53196c151bdfed091a25618 /deckit/server.py
parent8ec2352c22780202fcd39982f1c3e65d2dae0cc1 (diff)
downloaddeck-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 'deckit/server.py')
-rw-r--r--deckit/server.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/deckit/server.py b/deckit/server.py
index 38de5d3..835b612 100644
--- a/deckit/server.py
+++ b/deckit/server.py
@@ -36,7 +36,7 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
from urllib.parse import parse_qs, unquote, urlparse, urlsplit
-from . import config, module, theme
+from . import config, module, sleep, theme
ROOT = Path(__file__).resolve().parent.parent
STATIC = ROOT / "static"
@@ -153,6 +153,8 @@ class Handler(BaseHTTPRequestHandler):
self.send_header("Content-Type", ctype)
self.send_header("Content-Length", str(len(body)))
self.send_header("Cache-Control", "max-age=86400" if cache else "no-store")
+ if sleep.sleeping.is_set():
+ self.send_header("X-Deckit-Sleep", "1") # the tablet shows "asleep" at once
self.end_headers()
self.wfile.write(body)
@@ -258,6 +260,7 @@ def serve():
TOKEN = load_token()
REGISTRY = build(CFG)
REGISTRY.start_all()
+ threading.Thread(target=sleep.watch, daemon=True).start()
RUNDIR.mkdir(mode=0o700, parents=True, exist_ok=True)
RUNDIR.chmod(0o700)
SOCKET.unlink(missing_ok=True)