Top bar layout, adaptive sidebar menu and custom logo
- logo and DSP choice on the left, menu and buttons on the right - the menu becomes a sidebar when it no longer fits in the top bar (measured, so it works for every language and device name); phones keep the bottom bar with short labels - custom logo in the settings: any PNG/JPG/WebP/SVG is scaled to a 128x128 PNG, shown top left and as the browser icon, stored by the server and in the backup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a85f62225
commit
cf0adc01fe
6 files changed
+151
-10
No files matched your search
@@ -90,6 +90,15 @@ def clean_limiter(data: dict) -> dict:
|
||||
return {"amps": amps, "assign": assign, "ref": ref}
|
||||
|
||||
|
||||
LOGO_MAX = 300_000 # characters of the data URL (the app sends a 128×128 PNG)
|
||||
|
||||
|
||||
def clean_logo(v) -> str:
|
||||
"""Custom logo as a PNG data URL, "" = the built-in one."""
|
||||
v = str(v or "")
|
||||
return v if v.startswith("data:image/png;base64,") and len(v) <= LOGO_MAX and re.fullmatch(r"[\w+/=]*", v[22:]) else ""
|
||||
|
||||
|
||||
SF_ROLES = ("main", "sub", "delay", "fill")
|
||||
|
||||
|
||||
@@ -171,6 +180,7 @@ class App:
|
||||
self.failures: dict[str, tuple[int, float]] = {} # ip -> (failed attempts, locked until)
|
||||
self.limiter: dict = clean_limiter({})
|
||||
self.soundfield: dict = clean_soundfield({})
|
||||
self.logo = ""
|
||||
# desktop app: its own window logs in with a one-time token, other devices need the PIN
|
||||
self.app_token: str | None = None
|
||||
self.app_sessions: set[str] = set()
|
||||
@@ -217,6 +227,8 @@ class App:
|
||||
self.limiter = clean_limiter(cfg.get("limiter") or {})
|
||||
if "soundfield" in cfg:
|
||||
self.soundfield = clean_soundfield(cfg.get("soundfield"))
|
||||
if "logo" in cfg:
|
||||
self.logo = clean_logo(cfg.get("logo"))
|
||||
r = cfg.get("remote") or {}
|
||||
self.remote = {"enabled": bool(r.get("enabled")), "port": int(_num(r.get("port"), 1, 65535, 8080))}
|
||||
for d in cfg.get("devices", [])[:20]:
|
||||
@@ -230,7 +242,7 @@ class App:
|
||||
"""App backup: devices, PIN (hashed), amplifiers/limiter data, remote access - no logins."""
|
||||
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}
|
||||
"limiter": self.limiter, "remote": self.remote, "soundfield": self.soundfield, "logo": self.logo}
|
||||
|
||||
async def restore_config(self, doc: dict, session: str):
|
||||
if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT:
|
||||
@@ -248,6 +260,7 @@ class App:
|
||||
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
|
||||
self.broadcast({"type": "limiter", "data": self.limiter})
|
||||
self.broadcast({"type": "soundfield", "data": self.soundfield})
|
||||
self.broadcast({"type": "logo", "data": self.logo})
|
||||
if self.app_token: # desktop app: (re)start or stop the LAN listener as restored
|
||||
await self.start_remote()
|
||||
|
||||
@@ -287,7 +300,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,
|
||||
"soundfield": self.soundfield,
|
||||
"soundfield": self.soundfield, "logo": self.logo,
|
||||
"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:
|
||||
@@ -665,6 +678,15 @@ class App:
|
||||
return [d.snapshot() for d in self.devices.values()]
|
||||
if path == "/api/devices" and method == "POST":
|
||||
return self.add_device(body).snapshot()
|
||||
if path == "/api/logo" and method == "PUT":
|
||||
self.logo = clean_logo(body.get("logo"))
|
||||
if body.get("logo") and not self.logo:
|
||||
raise ValueError("The logo could not be read")
|
||||
self.save()
|
||||
self.broadcast({"type": "logo", "data": self.logo})
|
||||
return {"logo": self.logo}
|
||||
if path == "/api/logo":
|
||||
return {"logo": self.logo}
|
||||
if path == "/api/soundfield" and method == "PUT":
|
||||
self.soundfield = clean_soundfield(body)
|
||||
self.save()
|
||||
@@ -951,7 +973,7 @@ class App:
|
||||
self.clients.add(q)
|
||||
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}
|
||||
"demo": self.demo_info(), "muteall": self.mute_all_info(), "soundfield": self.soundfield, "logo": self.logo}
|
||||
writer.write(f"data: {json.dumps(hello)}\n\n".encode())
|
||||
await writer.drain()
|
||||
while True:
|
||||
|
||||
Reference in new issue
Block a user