diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-12 09:01:06 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-12 09:01:06 +0100 |
| commit | 512a2b4a2821a1edadf5530d060e3ae5468d75e8 (patch) | |
| tree | f81dcb1d2238403bdcf68cf9298cc34b6a010672 /deckit/modules/tablet.py | |
| parent | fea2e9b221a2d18f9c73e5763adf662128cea5ec (diff) | |
| download | deck-it-512a2b4a2821a1edadf5530d060e3ae5468d75e8.tar.gz deck-it-512a2b4a2821a1edadf5530d060e3ae5468d75e8.zip | |
fix(tablet): restore the backlight after a restart or shutdown
The server never ran the modules' stop: `deck-it stop` ends it with
SIGTERM and nothing called stop_all, so a shutdown left the tablet dim.
A SIGTERM handler now runs stop_all before exiting.
The settings from before a dim lived only in memory, so a new server's
undim had nothing to put back. They are now kept in
~/.cache/deck-it/dim, and a freshly loaded page asks for undim, since it
is never dimmed itself.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'deckit/modules/tablet.py')
| -rw-r--r-- | deckit/modules/tablet.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/deckit/modules/tablet.py b/deckit/modules/tablet.py index 01a5eba..71f7a95 100644 --- a/deckit/modules/tablet.py +++ b/deckit/modules/tablet.py @@ -24,11 +24,15 @@ import re import subprocess import threading import time +from pathlib import Path from ..module import Module, ModuleError STATUS = {"2": "charging", "3": "discharging", "4": "not charging", "5": "full"} TTL = 10 # seconds; each read is two adb round trips +# The settings from before a dim, kept on disk so a server that died or a PC +# that rebooted while the tablet was dim can still put them back. +DIM_FILE = Path.home() / ".cache" / "deck-it" / "dim" def _adb(*args, timeout=5): @@ -109,6 +113,10 @@ def make(cfg: dict) -> Module: dim_after = max(0, int(tcfg.get("dim_after", 120))) level = min(255, max(0, int(tcfg.get("dim_brightness", 8)))) saved = {} # mode and brightness from before a dim; empty while bright + try: + saved["mode"], saved["level"] = DIM_FILE.read_text().split() + except (OSError, ValueError): + saved.clear() def shell(cmd): serial = cache["serial"] or _find_tablet() @@ -126,17 +134,18 @@ def make(cfg: dict) -> Module: if not saved: saved["mode"] = shell("settings get system screen_brightness_mode") saved["level"] = shell("settings get system screen_brightness") + DIM_FILE.parent.mkdir(parents=True, exist_ok=True) + DIM_FILE.write_text(f"{saved['mode']} {saved['level']}\n") shell(f"settings put system screen_brightness_mode 0;" f" settings put system screen_brightness {level}") - # ponytail: the saved level lives in memory; a crash while dimmed leaves - # the tablet dim until its brightness is raised by hand. def undim(_=None): with lock: if saved: shell(f"settings put system screen_brightness {int(saved['level'])};" f" settings put system screen_brightness_mode {int(saved['mode'])}") saved.clear() + DIM_FILE.unlink(missing_ok=True) def stop(): try: |
