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
+75
-3
@@ -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":
|
||||
|
||||
Reference in new issue
Block a user