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:
GivouandClaude Opus 5.5 committed 2026-11-01 23:07:53 +01:00
1 parent 3a85f62225
commit cf0adc01fe
6 files changed
+151 -10

No files matched your search

+75 -3
View File
@@ -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":
+11
View File
@@ -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 = [
+2 -2
View File
@@ -25,8 +25,8 @@
<button data-view="routing"><svg viewBox="0 0 24 24"><path d="M4 6h16M4 12h16M4 18h16M8 3v18M16 3v18"/><circle cx="8" cy="6" r="2.2" class="f"/><circle cx="16" cy="12" r="2.2" class="f"/><circle cx="8" cy="18" r="2.2" class="f"/></svg><span>Routing</span></button>
<button data-view="link"><svg viewBox="0 0 24 24"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/></svg><span>Link</span></button>
<button data-view="limiter"><svg viewBox="0 0 24 24"><path d="M2 7h20" stroke-dasharray="2.5 2.5"/><path d="M2 14c2 0 3-7 5-7h3c2 0 3 11 6 11s3-5 6-5"/></svg><span>Limiter</span></button>
<button data-view="soundfield"><svg viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M8 7l-2 2 2 2M16 7l2 2-2 2"/><path d="M7 15.5a7 7 0 0 1 10 0" stroke-dasharray="2 2"/><circle cx="12" cy="18" r="1.2" class="f"/></svg><span>SoundField</span></button>
<button data-view="test"><svg viewBox="0 0 24 24"><path d="M4 9v6h4l5 4V5L8 9z"/><path d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12"/></svg><span data-t="Audio test">Audio test</span></button>
<button data-view="soundfield"><svg viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M8 7l-2 2 2 2M16 7l2 2-2 2"/><path d="M7 15.5a7 7 0 0 1 10 0" stroke-dasharray="2 2"/><circle cx="12" cy="18" r="1.2" class="f"/></svg><span>SoundField</span><span class="short">Field</span></button>
<button data-view="test"><svg viewBox="0 0 24 24"><path d="M4 9v6h4l5 4V5L8 9z"/><path d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12"/></svg><span data-t="Audio test">Audio test</span><span class="short" data-t="Test">Test</span></button>
</nav>
<button id="btn-muteall" class="icon" aria-label="Mute all" title="Mute all"></button>
<button id="btn-lock" class="icon" hidden aria-label="Lock" title="Lock"></button>
+36 -2
View File
@@ -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; }