From d6be627f3262871918a3e54076461de46a617e8f Mon Sep 17 00:00:00 2001 From: Givou Date: Mon, 2 Nov 2026 18:45:38 +0100 Subject: [PATCH] DJ Brake: note that the limiter is not the goal, with its own settings Shown by default and always in English by default; both can be switched. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- server.py | 19 ++++++++++++++----- static/app.js | 19 +++++++++++++++++-- static/djbrake.html | 8 +++++++- static/i18n.js | 2 ++ static/style.css | 2 ++ 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a356e75..2d592c4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -58,7 +58,7 @@ pi_writer.py → pi_image.py (cloud-init SD card, installs server.py as a system * **Sound Lab / REW** (`static/rew.js`, handbooks in `static/docs.js`, `rew_call` in `server.py`) – the server talks to REW's API on `127.0.0.1:4735`, which only answers on REW's own computer; so Sound Lab is only in the desktop apps (`S.isApp`, the server refuses `/api/rew/` otherwise). Only checked against a fake server built from its OpenAPI spec. * **DJ Brake** (`static/djbrake.html`, `App.dj_stream`) – the only page without a login, off by default. It may only ever learn - `{on, ready, room}` from `/djbrake/state`: never add device data or controls there. On its own on purpose, without `app.js`. + `{on, ready, room, hint}` from `/djbrake/state`: never add device data or controls there. On its own on purpose, without `app.js`. * **Network search** – `App.scan_network` probes the local /24 networks on TCP 9761 (handshake + device info), skipping DSPs this app is connected to. * **Copy settings / mute all** – `App.copy_settings` (`POST /api/copy`, groups level/filters/eq/dynamics/routing) and diff --git a/server.py b/server.py index 5d367fa..33be4aa 100644 --- a/server.py +++ b/server.py @@ -306,6 +306,8 @@ class App: self.dashboard: dict | None = None self.djbrake = False # page /djbrake for the DJ: without PIN, shows only whether a limiter acts self.dj_ignore: dict = {} # device id -> outputs not watched + self.dj_hint = True # short text on the page: the limiter is not the goal + self.dj_hint_en = True # that text always in English, else in the language of the browser self.dj_hit = 0.0 # when a limiter was last seen acting self.dj_rooms: dict = {} # device id -> dB left to the nearest watched limiter, False = nothing watched self.dj_streams = 0 @@ -359,6 +361,8 @@ class App: self.dashboard = clean_dashboard(cfg.get("dashboard")) self.djbrake = bool(cfg.get("djbrake")) self.dj_ignore = clean_dj_ignore(cfg.get("dj_ignore")) + self.dj_hint = bool(cfg.get("dj_hint", True)) + self.dj_hint_en = bool(cfg.get("dj_hint_en", True)) if "logo" in cfg: self.logo = clean_logo(cfg.get("logo")) r = cfg.get("remote") or {} @@ -375,7 +379,7 @@ class App: return {"format": CONFIG_FORMAT, "version": 1, "exported": time.strftime("%Y-%m-%dT%H:%M:%S"), "devices": [d.config() for d in self.real_devices()], "auth": self.auth, "limiter": self.limiter, "remote": self.remote, "soundfield": self.soundfield, "logo": self.logo, - "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore} + "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en} async def restore_config(self, doc: dict, session: str): if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT: @@ -433,7 +437,7 @@ class App: sessions = {k: v for k, v in self.sessions.items() if k not in self.app_sessions} cfg = {"devices": [d.config() for d in self.real_devices()], "auth": self.auth, "sessions": sessions, "limiter": self.limiter, "remote": self.remote, "locked": self.locked, "lock_dash": self.lock_dash, - "soundfield": self.soundfield, "logo": self.logo, "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, + "soundfield": self.soundfield, "logo": self.logo, "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en, "mute_all": {"active": self.mute_all["active"], "restore": {k: v for k, v in self.mute_all["restore"].items() if k != "demo"}}} if self.lang: @@ -937,8 +941,12 @@ class App: self.djbrake = bool(body["enabled"]) if "ignore" in body: self.dj_ignore = clean_dj_ignore(body["ignore"]) + if "hint" in body: + self.dj_hint = bool(body["hint"]) + if "hint_en" in body: + self.dj_hint_en = bool(body["hint_en"]) self.save() - ans = {"enabled": self.djbrake, "ignore": self.dj_ignore} + ans = {"enabled": self.djbrake, "ignore": self.dj_ignore, "hint": self.dj_hint, "hint_en": self.dj_hint_en} self.broadcast({"type": "djbrake", **ans}) return ans if path == "/api/dashboard" and method == "PUT": @@ -1297,7 +1305,8 @@ class App: rooms = [r for r in rooms if r is not False] known = [r for r in rooms if r is not None] state = {"on": now - self.dj_hit < DJ_HOLD, "ready": bool(rooms), - "room": round(min(known) * 2) / 2 if known else None} + "room": round(min(known) * 2) / 2 if known else None, + "hint": ("en" if self.dj_hint_en else "auto") if self.dj_hint else None} if state != last: writer.write(f"data: {json.dumps(state)}\n\n".encode()) last, idle = state, 0.0 @@ -1318,7 +1327,7 @@ class App: try: hello = {"type": "hello", "devices": [d.snapshot() for d in self.devices.values()], "limiter": self.limiter, "demo": self.demo_info(), "muteall": self.mute_all_info(), "soundfield": self.soundfield, "logo": self.logo, - "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore} + "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en} writer.write(f"data: {json.dumps(hello)}\n\n".encode()) await writer.drain() while True: diff --git a/static/app.js b/static/app.js index 864f7c9..deb8df3 100644 --- a/static/app.js +++ b/static/app.js @@ -2385,9 +2385,24 @@ function djBrakeCard() { } }, t("Copy"))) : null, S.djbrake && !url ? h("p", { class: "info djwarn" }, t("Switch on remote access below so other devices can reach it.")) : null, S.djbrake ? djLimiters() : null, + S.djbrake ? djHintOptions() : null, S.djbrake ? h("p", { class: "info" }, t("Anyone in your network can open it without a PIN. It shows only the light and the distance to the limiter and changes nothing.")) : null); } +function djHintOptions() { + const save = async (key, on) => { + try { + const r = await api("PUT", "/api/djbrake", { [key]: on }); + S.djHint = r.hint; S.djHintEn = r.hint_en; render(); + } catch (e) { toast(t("Error: ") + trMsg(e.message)); render(); } + }; + return h("div", { class: "djlim" }, + h("label", { class: "chk" }, h("input", { type: "checkbox", checked: S.djHint, onchange: e => save("hint", e.target.checked) }), + t("Show a short note that the limiter is not the goal")), + S.djHint ? h("label", { class: "chk" }, h("input", { type: "checkbox", checked: S.djHintEn, onchange: e => save("hint_en", e.target.checked) }), + t("Note always in English")) : null); +} + function djLimiters() { const devs = S.order.map(id => S.devices[id]).filter(d => d.state && !d.demo); const toggle = async (id, i) => { @@ -2655,7 +2670,7 @@ function connectEvents() { if (ev.muteall) { S.muteAll = ev.muteall.active; showMuteAll(); } if (ev.soundfield) S.sf = ev.soundfield; if ("dashboard" in ev) S.dash = ev.dashboard && ev.dashboard.modules; - S.djbrake = !!ev.djbrake; S.djIgnore = ev.dj_ignore || {}; + S.djbrake = !!ev.djbrake; S.djIgnore = ev.dj_ignore || {}; S.djHint = ev.dj_hint !== false; S.djHintEn = ev.dj_hint_en !== false; if ("logo" in ev) { S.logo = ev.logo; showLogo(); } if (S.demo.enabled && S.devices.demo && !S.devices[S.cur]?.demo) S.cur = "demo"; S.order.forEach(id => maybeAskUnlock(S.devices[id])); @@ -2691,7 +2706,7 @@ function connectEvents() { case "dashboard": dashRemote(ev.data); break; case "djbrake": - S.djbrake = ev.enabled; S.djIgnore = ev.ignore; if (S.settings && !S.busy) render(); break; + S.djbrake = ev.enabled; S.djIgnore = ev.ignore; S.djHint = ev.hint; S.djHintEn = ev.hint_en; if (S.settings && !S.busy) render(); break; case "logo": S.logo = ev.data; showLogo(); if (S.settings) render(); break; case "muteall": diff --git a/static/djbrake.html b/static/djbrake.html index 1c1f4eb..d3bc419 100644 --- a/static/djbrake.html +++ b/static/djbrake.html @@ -9,7 +9,7 @@ DJ Brake