From cf0adc01fed29e1125645c5b4a5d979de6d86879 Mon Sep 17 00:00:00 2001 From: Givou Date: Sun, 1 Nov 2026 23:07:53 +0100 Subject: [PATCH] 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 --- README.md | 2 ++ server.py | 28 +++++++++++++++-- static/app.js | 78 +++++++++++++++++++++++++++++++++++++++++++++-- static/i18n.js | 11 +++++++ static/index.html | 4 +-- static/style.css | 38 +++++++++++++++++++++-- 6 files changed, 151 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1536717..5ecb2ca 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ Control both devices at the same time from your phone, tablet or computer – ov of channels on all connected DSPs * **Channel colours** – pick a colour per channel in the settings (line and lightly tinted name in the mixer, channel view, routing and curve overlays); linked channels share one colour, every colour is used once per DSP +* **Custom logo** – your own logo top left and as the browser icon (settings → Logo; PNG/JPG/WebP/SVG, ideally square, ≥ 64×64 px) +* **Fits every screen** – menu in the top bar on wide screens, a sidebar when the window gets narrow, a bottom bar on phones * **Mute all** – one button mutes every channel of every connected DSP; releasing it unmutes only what was open before * **Settings backup** – devices, amplifier data, SoundField plan, PIN and remote access in one file * **Device lock** – DSPs locked with their 4-character code (e.g. `A1BA`) are detected on connect and the app asks diff --git a/server.py b/server.py index b797145..f8b1b14 100644 --- a/server.py +++ b/server.py @@ -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: diff --git a/static/app.js b/static/app.js index 0ae4363..ca0df64 100644 --- a/static/app.js +++ b/static/app.js @@ -249,7 +249,7 @@ async function saveFile(name, obj) { } // -> { name, b64, json } (json = parsed content if the file is JSON, else null), or null if cancelled -async function openFile() { +async function openFile(accept = ".json,.bin,application/json,application/octet-stream") { let name, bytes; const papi = window.pywebview && window.pywebview.api; if (papi && papi.open_file) { @@ -258,7 +258,7 @@ async function openFile() { name = f.name; bytes = Uint8Array.from(atob(f.data), c => c.charCodeAt(0)); } else { const file = await new Promise(resolve => { - const inp = h("input", { type: "file", accept: ".json,.bin,application/json,application/octet-stream", hidden: true }); + const inp = h("input", { type: "file", accept, hidden: true }); inp.addEventListener("change", () => resolve(inp.files[0] || null)); document.body.append(inp); inp.click(); setTimeout(() => inp.remove(), 60000); }); @@ -572,6 +572,7 @@ function renderTabs() { b.classList.toggle("active", !S.settings && b.dataset.view === S.view); b.disabled = testLock && b.dataset.view !== "test"; }); + fitNav(); // the DSP button's width changes with the name } // close the DSP menu on a click elsewhere or Escape document.addEventListener("pointerdown", e => { if (S.devMenu && !e.target.closest("#devtabs")) { S.devMenu = false; renderTabs(); } }); @@ -1923,6 +1924,60 @@ function pinCard() { : t("The default PIN is 1234. After changing it only this device stays logged in."))); } +// ------------------------------------------------------------------ custom logo (top left and browser icon) + +const LOGO_PX = 128, LOGO_MIN = 64; +const DEFAULT_LOGO = $(".brand").innerHTML; +function showLogo() { + const b = $(".brand"); + b.replaceChildren(); + if (S.logo) b.append(h("img", { src: S.logo, alt: "", width: 26, height: 26 })); + else b.innerHTML = DEFAULT_LOGO; + let icon = document.querySelector("link[rel=icon]"); + if (!icon) { icon = h("link", { rel: "icon" }); document.head.append(icon); } + if (S.logo) icon.href = S.logo; else icon.removeAttribute("href"); +} + +// any picture -> 128×128 PNG, centred without distortion (transparent where it isn't square) +async function logoFromFile() { + const f = await openFile(".png,.jpg,.jpeg,.webp,.svg,.gif,image/*"); + if (!f) return null; + const ext = (f.name.split(".").pop() || "").toLowerCase(); + const mime = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", svg: "image/svg+xml" }[ext]; + if (!mime) throw new Error(t("Please choose a PNG, JPG, WebP or SVG image")); + const img = new Image(); + await new Promise((ok, bad) => { img.onload = ok; img.onerror = () => bad(new Error(t("The logo could not be read"))); img.src = `data:${mime};base64,${f.b64}`; }); + const w = img.naturalWidth || LOGO_PX, hh = img.naturalHeight || LOGO_PX; // SVGs without a size count as fine + if (mime !== "image/svg+xml" && (w < LOGO_MIN || hh < LOGO_MIN)) throw new Error(t("The image is too small – at least {n}×{n} pixels", { n: LOGO_MIN })); + const cv = h("canvas", { width: LOGO_PX, height: LOGO_PX }), g = cv.getContext("2d"), sc = Math.min(LOGO_PX / w, LOGO_PX / hh); + g.imageSmoothingQuality = "high"; + g.drawImage(img, (LOGO_PX - w * sc) / 2, (LOGO_PX - hh * sc) / 2, w * sc, hh * sc); + return { url: cv.toDataURL("image/png"), square: Math.abs(w - hh) <= Math.max(w, hh) * 0.02 }; +} + +function logoCard() { + const preview = h("div", { class: "logoprev" }); + if (S.logo) preview.append(h("img", { src: S.logo, alt: "" })); else preview.innerHTML = DEFAULT_LOGO; + const set = async logo => { + try { S.logo = (await api("PUT", "/api/logo", { logo })).logo; showLogo(); render(); } + catch (e) { toast(t("Error: ") + trMsg(e.message)); } + }; + return h("div", { class: "card" }, h("h3", {}, t("Logo")), + h("div", { class: "row logorow" }, preview, + h("div", { class: "grow" }, + h("p", { class: "info" }, t("Your own logo top left (and as the browser icon). PNG, JPG, WebP or SVG, ideally square, at least 64×64 pixels, transparent background recommended. It is scaled to 128×128 pixels; other shapes are centred without distortion.")))), + h("div", { class: "actions" }, + h("button", { class: "on", onclick: async () => { + try { + const r = await logoFromFile(); + if (!r) return; + await set(r.url); + toast(r.square ? t("Logo replaced") : t("Logo replaced – the image was not square and has been centred")); + } catch (e) { toast(trMsg(e.message)); } + } }, t("Choose image…")), + S.logo ? h("button", { onclick: () => set("") }, t("Default logo")) : null)); +} + // Language per device (stored in the browser); the desktop app also tells the server, for its own dialogs function langCard() { const set = async lang => { @@ -1938,7 +1993,7 @@ function langCard() { function viewSettings() { return [ - h("div", { class: "cards" }, langCard(), demoCard()), + h("div", { class: "cards" }, langCard(), demoCard(), logoCard()), h("h2", { class: "section" }, t("Devices")), h("div", { class: "cards" }, ...S.order.filter(id => !S.devices[id].demo).map(id => deviceForm(S.devices[id])), deviceForm(null)), h("p", { class: "info" }, t("Both DSPs can be connected at the same time – switch between them at the top. "), @@ -2000,6 +2055,20 @@ document.querySelectorAll("#viewtabs button").forEach(b => b.addEventListener("c })); $("#btn-settings").addEventListener("click", () => { if (testOn(dev())) return; S.settings = !S.settings; render(); window.scrollTo(0, 0); }); +// menu at the top while it fits next to the DSP choice, otherwise a sidebar on the left (phones: bottom bar) +function fitNav() { + const top = $("#top"), b = document.body; + if (window.innerWidth < 760) { b.classList.remove("navside"); return; } + b.classList.remove("navside"); // measure the one-row layout (no paint happens in between) + const kids = [...top.children].filter(el => !el.hidden && getComputedStyle(el).display !== "none"); + const cs = getComputedStyle(top), gap = parseFloat(cs.columnGap) || 0; + // natural widths: the DSP button may be squeezed by flexbox, so take its content width + const need = kids.reduce((w, el) => w + (el.id === "devtabs" ? el.scrollWidth : el.getBoundingClientRect().width), 0) + + gap * (kids.length - 1) + parseFloat(cs.paddingLeft) + parseFloat(cs.paddingRight); + if (need > top.clientWidth + 1) b.classList.add("navside"); +} +window.addEventListener("resize", fitNav); + // header / status bar heights -> CSS vars (sticky channel bar, fader height that fits the screen) new ResizeObserver(() => { document.documentElement.style.setProperty("--hdr", $("#top").offsetHeight + "px"); @@ -2074,6 +2143,7 @@ function connectEvents() { if (ev.demo) S.demo = ev.demo; if (ev.muteall) { S.muteAll = ev.muteall.active; showMuteAll(); } if (ev.soundfield) S.sf = ev.soundfield; + 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])); if (!S.order.length) S.settings = true; @@ -2103,6 +2173,8 @@ function connectEvents() { } case "soundfield": sfOnRemote(ev.data); break; + case "logo": + S.logo = ev.data; showLogo(); if (S.settings) render(); break; case "muteall": S.muteAll = ev.data.active; showMuteAll(); break; case "demo": diff --git a/static/i18n.js b/static/i18n.js index 1f3b673..ede16af 100644 --- a/static/i18n.js +++ b/static/i18n.js @@ -455,6 +455,17 @@ const DE = { "Sub with a top on a distance pole": "Sub mit Top auf Distanzstange", "Add a DSP…": "DSP hinzufügen…", "simulated": "simuliert", + // logo + "Logo": "Logo", + "Your own logo top left (and as the browser icon). PNG, JPG, WebP or SVG, ideally square, at least 64×64 pixels, transparent background recommended. It is scaled to 128×128 pixels; other shapes are centred without distortion.": "Eigenes Logo oben links (und als Browser-Symbol). PNG, JPG, WebP oder SVG, am besten quadratisch, mindestens 64×64 Pixel, transparenter Hintergrund empfohlen. Es wird auf 128×128 Pixel skaliert; andere Formate werden unverzerrt zentriert.", + "Choose image…": "Bild wählen…", + "Default logo": "Standard-Logo", + "Logo replaced": "Logo ersetzt", + "Logo replaced – the image was not square and has been centred": "Logo ersetzt – das Bild war nicht quadratisch und wurde zentriert", + "Please choose a PNG, JPG, WebP or SVG image": "Bitte ein PNG-, JPG-, WebP- oder SVG-Bild wählen", + "The logo could not be read": "Das Logo konnte nicht gelesen werden", + "The image is too small – at least {n}×{n} pixels": "Das Bild ist zu klein – mindestens {n}×{n} Pixel", + "Test": "Test", }; const DE_PATTERNS = [ diff --git a/static/index.html b/static/index.html index 1d4d77e..e362834 100644 --- a/static/index.html +++ b/static/index.html @@ -25,8 +25,8 @@ - - + + diff --git a/static/style.css b/static/style.css index 5680396..f2f88b7 100644 --- a/static/style.css +++ b/static/style.css @@ -79,7 +79,8 @@ label.inline { display: flex; align-items: center; gap: 8px; font-size: 13px; co .dot.error { background: var(--bad); } @keyframes blink { 50% { opacity: .3; } } -#viewtabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 3px; flex: none; } +#viewtabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 3px; flex: none; + margin-left: auto; } /* logo + DSP choice on the left, menu and buttons on the right */ #viewtabs button { border: 0; background: none; min-height: 36px; padding: 6px 14px; color: var(--dim); border-radius: 8px; } #viewtabs button svg { width: 18px; height: 18px; } #viewtabs button svg .f { fill: currentColor; stroke: none; } @@ -100,7 +101,8 @@ body[data-view=settings] #viewtabs button.active { background: none; color: var( /* phones: view switcher becomes a bottom navigation bar */ @media (max-width: 759px) { :root { --bnav: calc(62px + env(safe-area-inset-bottom)); } - .brand { display: none; } + .brand img, .brand svg { width: 24px; height: 24px; } + #btn-muteall { margin-left: auto; } /* the menu moved to the bottom bar: buttons stay on the right */ /* backdrop-filter would make the header the containing block of the fixed bottom bar */ #top { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); } #viewtabs { @@ -607,3 +609,35 @@ button.devitem .dn { flex: 1; text-align: left; overflow: hidden; text-overflow: button.devitem .where { font-size: 11px; color: var(--dim); } button.devitem small { font-size: 11px; color: var(--dim); background: var(--panel3); border-radius: 5px; padding: 1px 5px; } button.devitem.paused, button.devitem:disabled { opacity: .45; cursor: not-allowed; } + +/* ---- custom logo */ +.brand img { width: 26px; height: 26px; object-fit: contain; border-radius: 6px; display: block; } +.logorow { align-items: flex-start; gap: 14px; } +.logoprev { width: 72px; height: 72px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 12px; + background: repeating-conic-gradient(#ffffff10 0 25%, transparent 0 50%) 0 0 / 14px 14px, var(--panel2); border: 1px solid var(--line); } +.logoprev img, .logoprev svg { width: 56px; height: 56px; object-fit: contain; } + +/* ---- menu as a sidebar when the top bar is too narrow (tablets, small windows) */ +:root { --side: 92px; } +@media (min-width: 760px) { + body.navside #viewtabs { position: fixed; top: var(--hdr); left: 0; bottom: 0; width: var(--side); z-index: 15; margin: 0; + flex-direction: column; gap: 4px; padding: 8px 6px max(8px, env(safe-area-inset-bottom)); overflow-y: auto; + border: 0; border-right: 1px solid var(--line); border-radius: 0; background: var(--panel); } + body.navside #viewtabs button { flex-direction: column; gap: 4px; width: 100%; min-height: 60px; padding: 8px 4px; font-size: 11px; + line-height: 1.15; text-align: center; white-space: normal; } + body.navside #viewtabs button svg { width: 22px; height: 22px; } + body.navside #statusbar, body.navside #main { margin-left: var(--side); } + body.navside #main { max-width: none; } + body.navside #btn-muteall { margin-left: auto; } + /* backdrop-filter would make the header the containing block of the fixed sidebar */ + body.navside #top { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); } +} +/* phones: all menu items fit in the bottom bar, long labels are shortened */ +@media (max-width: 759px) { + #viewtabs button { min-width: 0; font-size: 10px; letter-spacing: 0; } + #viewtabs button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + #viewtabs button:has(.short) > span:not(.short) { display: none; } /* long labels: short form in the bottom bar */ + #viewtabs button span.short { display: inline; } +} +#viewtabs button .short { display: none; } +.logorow + .actions { margin-top: 12px; }