Add device lock support and demo mode
Device lock (hardware lock of the DSP, independent of the app lock): - detect a locked DSP from the 0x2C answer during connect and wait for the code - unlock with 0x2D, optionally remember the code and unlock automatically - set a new code (0x2F) from the device settings - simulator: --lock CODE Demo mode: - switch in the settings starts a simulated DSP 204/408 inside the server - real DSPs are disconnected and greyed out meanwhile and resume afterwards - demo devices are never saved or exported; sim.py ships with the Pi image and EXEs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fe13f261f7
commit
61400df667
13 files changed
+426
-38
No files matched your search
+129
-13
@@ -60,6 +60,7 @@ const S = {
|
||||
sel: { kind: "in", idx: 0 }, band: 0, busy: false, dirty: false,
|
||||
routeOpen: null, es: null, linkSel: { in: [], out: [] },
|
||||
lim: { amps: [], assign: {}, ref: {} },
|
||||
demo: { enabled: false, model: "408" },
|
||||
};
|
||||
const $ = sel => document.querySelector(sel);
|
||||
const main = $("#main");
|
||||
@@ -510,19 +511,116 @@ requestAnimationFrame(meterFrame);
|
||||
|
||||
function renderTabs() {
|
||||
const tabs = $("#devtabs");
|
||||
tabs.replaceChildren(...S.order.map(id => {
|
||||
const order = [...S.order].sort((a, b) => !!S.devices[b].demo - !!S.devices[a].demo); // demo tab first
|
||||
tabs.replaceChildren(...order.map(id => {
|
||||
const d = S.devices[id];
|
||||
const model = d.detected_model || (d.model !== "auto" ? d.model : "");
|
||||
return h("button", { class: "devtab" + (id === S.cur && !S.settings ? " active" : ""), title: `${d.name} · ${where(d)}`,
|
||||
onclick: () => { S.cur = id; S.settings = false; store.set("dsp.cur", id); render(); } },
|
||||
h("span", { class: "dot " + d.status }), h("span", { class: "dn" }, d.name), model ? h("small", {}, model) : null);
|
||||
const paused = S.demo.enabled && !d.demo; // demo mode: the real DSPs are disconnected
|
||||
return h("button", { class: "devtab" + (id === S.cur && !S.settings ? " active" : "") + (paused ? " paused" : "") + (d.demo ? " demo" : ""),
|
||||
title: paused ? t("Disconnected while demo mode is on") : d.demo ? t("Demo mode – simulated DSP") : `${d.name} · ${where(d)}`,
|
||||
disabled: paused, onclick: () => { S.cur = id; S.settings = false; store.set("dsp.cur", id); render(); } },
|
||||
h("span", { class: "dot " + d.status }), h("span", { class: "dn" }, d.name),
|
||||
d.demo ? h("small", { class: "demo-badge" }, "DEMO") : model ? h("small", {}, model) : null);
|
||||
}));
|
||||
$("#btn-settings").classList.toggle("on", S.settings);
|
||||
document.querySelectorAll("#viewtabs button").forEach(b => b.classList.toggle("active", !S.settings && b.dataset.view === S.view));
|
||||
}
|
||||
|
||||
const STATUS_TEXT = { disconnected: t("Disconnected"), connecting: t("Connecting…"), loading: t("Loading configuration…"),
|
||||
online: "Online", error: t("Error") };
|
||||
locked: t("Locked with a code"), online: "Online", error: t("Error") };
|
||||
|
||||
// ------------------------------------------------------------------ hardware lock of the DSP (not the app lock)
|
||||
|
||||
const LOCK_RE = /^[A-Z0-9]{4}$/;
|
||||
const codeInput = () => {
|
||||
const el = h("input", { type: "text", maxlength: 4, autocomplete: "off", autocapitalize: "characters", spellcheck: "false",
|
||||
class: "code", placeholder: "A1B2", "aria-label": t("Lock code") });
|
||||
el.addEventListener("input", () => { el.value = el.value.toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 4); });
|
||||
return el;
|
||||
};
|
||||
|
||||
async function unlockDialog(d) {
|
||||
let error = "";
|
||||
for (;;) {
|
||||
const code = codeInput();
|
||||
const remember = h("input", { type: "checkbox", checked: !!d.auto_unlock || !d.lock_code });
|
||||
const res = await modal({
|
||||
title: t("DSP locked"),
|
||||
body: h("div", {},
|
||||
h("p", { class: "dlg-text" }, t("{name} is locked with a code. Enter the 4-character code (digits and letters A–Z).", { name: q(d.name) })),
|
||||
code,
|
||||
error ? h("div", { class: "err" }, error) : null,
|
||||
h("label", { class: "chk" }, remember, t("Remember the code and unlock automatically"))),
|
||||
actions: [{ label: t("Cancel") },
|
||||
{ label: t("Unlock"), primary: true, value: () => LOCK_RE.test(code.value) ? { code: code.value, remember: remember.checked } : (code.focus(), undefined) }],
|
||||
});
|
||||
if (!res) return false;
|
||||
try {
|
||||
const r = await api("POST", `/api/devices/${d.id}/unlock`, res);
|
||||
if (r.ok) { toast(t("DSP unlocked")); return true; }
|
||||
error = t("Wrong code – please try again.");
|
||||
} catch (e) { error = trMsg(e.message); }
|
||||
}
|
||||
}
|
||||
|
||||
// ask once per lock episode when the DSP on screen turns out to be locked
|
||||
const lockAsked = new Set();
|
||||
function maybeAskUnlock(d) {
|
||||
if (d.status !== "locked") { lockAsked.delete(d.id); return; }
|
||||
if (lockAsked.has(d.id) || d.id !== S.cur || S.settings || S.locked) return;
|
||||
lockAsked.add(d.id);
|
||||
setTimeout(() => unlockDialog(S.devices[d.id] || d), 50);
|
||||
}
|
||||
|
||||
const lockOpen = new Set(); // device ids whose lock section is open (survives re-rendering)
|
||||
function lockSection(d) {
|
||||
const online = d.status === "online";
|
||||
const auto = h("input", { type: "checkbox", checked: !!d.auto_unlock, disabled: !d.lock_code,
|
||||
onchange: () => api("PUT", `/api/devices/${d.id}`, { auto_unlock: auto.checked }).catch(e => toast(e.message)) });
|
||||
const code = codeInput();
|
||||
const setCode = async () => {
|
||||
if (!LOCK_RE.test(code.value)) { code.focus(); return toast(t("The code has 4 characters: digits and letters A–Z")); }
|
||||
if (!await askConfirm(t("Set lock code"), t("From the next connection on, {name} asks for the code {code} – also in the original software. Note it down: this app cannot remove the lock again.",
|
||||
{ name: q(d.name), code: code.value }), t("Set code"), true)) return;
|
||||
try { await api("POST", `/api/devices/${d.id}/lockcode`, { code: code.value }); toast(t("Lock code set")); }
|
||||
catch (e) { toast(t("Error: ") + trMsg(e.message)); }
|
||||
};
|
||||
const box = h("details", { class: "more full lockbox", open: lockOpen.has(d.id),
|
||||
ontoggle: () => box.open ? lockOpen.add(d.id) : lockOpen.delete(d.id) },
|
||||
h("summary", {}, t("Device lock (code)"), d.lock_code ? h("span", { class: "tag" }, t("code remembered")) : null),
|
||||
h("p", { class: "info" }, t("Hardware lock of the DSP: a locked DSP only accepts a connection after its code was entered. Independent of the lock of this app.")),
|
||||
h("label", { class: "chk" }, auto, t("Unlock automatically with the remembered code")),
|
||||
d.lock_code
|
||||
? h("div", { class: "row" }, h("span", { class: "grow info" }, t("A code is remembered for this DSP.")),
|
||||
h("button", { class: "small", onclick: () => api("PUT", `/api/devices/${d.id}`, { lock_code: "" }).then(() => toast(t("Code forgotten"))).catch(e => toast(e.message)) }, t("Forget code")))
|
||||
: h("div", { class: "info" }, t("No code remembered – it is asked for when the DSP is locked.")),
|
||||
h("div", { class: "sub" }, t("Set a new lock code")),
|
||||
h("div", { class: "row" }, code, h("button", { class: "small", disabled: !online, onclick: setCode }, t("Set code"))),
|
||||
online ? null : h("div", { class: "info" }, t("Connect the DSP to set a code.")));
|
||||
return box;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ demo mode
|
||||
|
||||
async function setDemo(body) {
|
||||
try {
|
||||
S.demo = await api("PUT", "/api/demo", body);
|
||||
if (S.demo.enabled) { S.cur = "demo"; S.settings = false; S.view = "mixer"; }
|
||||
render();
|
||||
} catch (e) { toast(t("Error: ") + trMsg(e.message)); }
|
||||
}
|
||||
|
||||
function demoCard() {
|
||||
const on = S.demo.enabled;
|
||||
return h("div", { class: "card" + (on ? " demo-on" : "") },
|
||||
h("h3", {}, h("span", { class: "grow" }, t("Demo mode")), on ? h("span", { class: "demo-badge" }, "DEMO") : null),
|
||||
h("p", { class: "info" }, t("Try everything with a simulated DSP – nothing is sent to real devices. While demo mode is on, the real DSPs are disconnected.")),
|
||||
h("div", { class: "row" },
|
||||
h("div", { class: "seg grow" }, [[false, t("Off")], [true, t("On")]].map(([v, label]) =>
|
||||
h("button", { class: v === on ? "on" : "", "aria-pressed": String(v === on), onclick: () => v !== on && setDemo({ enabled: v }) }, label))),
|
||||
h("div", { class: "seg" }, ["204", "408"].map(m =>
|
||||
h("button", { class: m === S.demo.model ? "on" : "", onclick: () => m !== S.demo.model && setDemo({ model: m }) }, "DSP " + m)))));
|
||||
}
|
||||
|
||||
async function storePresetDialog(d) {
|
||||
const slot = h("select", {}, d.presets.map((p, i) => h("option", { value: i }, `U${String(i + 1).padStart(2, "0")} ${p || t("— empty —")}`)));
|
||||
@@ -603,8 +701,11 @@ function renderStatus() {
|
||||
bar.replaceChildren(
|
||||
h("div", { class: "preset" }, h("small", {}, `${STATUS_TEXT[d.status] || d.status} · ${d.transport === "usb" ? "USB" : d.host + ":" + d.port}`), h("b", {}, d.name),
|
||||
d.error ? h("div", { class: "err" }, trMsg(d.error)) : null),
|
||||
d.status === "disconnected" || d.status === "error"
|
||||
? h("button", { class: "on", onclick: () => api("POST", `/api/devices/${d.id}/connect`).catch(e => toast(e.message)) }, t("Connect"))
|
||||
d.status === "locked"
|
||||
? h("div", { class: "presetrow" }, h("button", { class: "on", onclick: () => unlockDialog(d) }, t("Enter code")),
|
||||
h("button", { onclick: () => api("POST", `/api/devices/${d.id}/disconnect`) }, t("Disconnect")))
|
||||
: d.status === "disconnected" || d.status === "error"
|
||||
? h("button", { class: "on", disabled: S.demo.enabled && !d.demo, onclick: () => api("POST", `/api/devices/${d.id}/connect`).catch(e => toast(trMsg(e.message))) }, t("Connect"))
|
||||
: h("button", { onclick: () => api("POST", `/api/devices/${d.id}/disconnect`) }, t("Cancel")));
|
||||
return;
|
||||
}
|
||||
@@ -622,7 +723,7 @@ function renderStatus() {
|
||||
presetSel.disabled = false;
|
||||
});
|
||||
bar.replaceChildren(
|
||||
h("div", { class: "preset" }, h("small", {}, `${d.info || d.name} · ${where(d)}`), h("b", {}, d.state.preset_name || "—")),
|
||||
h("div", { class: "preset" }, h("small", {}, d.demo ? t("Demo mode · simulated DSP") : `${d.info || d.name} · ${where(d)}`), h("b", {}, d.state.preset_name || "—")),
|
||||
h("div", { class: "presetrow" }, presetSel, h("button", { onclick: () => storePresetDialog(d) }, t("Save")),
|
||||
h("button", { onclick: () => presetFileDialog(d), title: t("Export / import preset"), "data-view-ok": "" }, t("File…"))));
|
||||
}
|
||||
@@ -1348,7 +1449,7 @@ function deviceForm(d) {
|
||||
: [
|
||||
h("button", { onclick: async () => { try { await api("PUT", `/api/devices/${d.id}`, values()); toast(t("Saved")); } catch (e) { toast(e.message); } } }, t("Save")),
|
||||
d.status === "disconnected" || d.status === "error"
|
||||
? h("button", { class: "on", onclick: async () => { // connects with what the form shows, saved or not
|
||||
? h("button", { class: "on", disabled: S.demo.enabled, onclick: async () => { // connects with what the form shows, saved or not
|
||||
try { await api("PUT", `/api/devices/${d.id}`, values()); await api("POST", `/api/devices/${d.id}/connect`); }
|
||||
catch (e) { toast(e.message); }
|
||||
} }, t("Connect"))
|
||||
@@ -1358,7 +1459,9 @@ function deviceForm(d) {
|
||||
await api("DELETE", `/api/devices/${d.id}`).catch(e => toast(e.message));
|
||||
} }, t("Remove")),
|
||||
];
|
||||
return h("div", { class: "card" },
|
||||
const paused = S.demo.enabled && !isNew;
|
||||
return h("div", { class: "card" + (paused ? " paused" : "") },
|
||||
paused ? h("div", { class: "info" }, t("Disconnected while demo mode is on")) : null,
|
||||
h("h3", {}, isNew ? null : h("span", { class: "dot " + d.status }), h("span", { class: "grow" }, isNew ? t("New device") : d.name),
|
||||
isNew ? null : h("span", { class: "info" }, STATUS_TEXT[d.status])),
|
||||
!isNew && d.info ? h("div", { class: "info" }, t("Device reports: ") + d.info) : null,
|
||||
@@ -1369,6 +1472,7 @@ function deviceForm(d) {
|
||||
...netRows, usbRow,
|
||||
h("label", {}, t("Model"), f.model),
|
||||
h("label", { class: "chk" }, f.autoconnect, t("Connect automatically")),
|
||||
isNew ? null : lockSection(d),
|
||||
h("div", { class: "actions" }, actions)));
|
||||
}
|
||||
|
||||
@@ -1471,9 +1575,9 @@ function langCard() {
|
||||
|
||||
function viewSettings() {
|
||||
return [
|
||||
h("div", { class: "cards" }, langCard()),
|
||||
h("div", { class: "cards" }, langCard(), demoCard()),
|
||||
h("h2", { class: "section" }, t("Devices")),
|
||||
h("div", { class: "cards" }, ...S.order.map(id => deviceForm(S.devices[id])), deviceForm(null)),
|
||||
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. "),
|
||||
t("The DSPs accept only one connection: close the Thomann editor first.")),
|
||||
h("h2", { class: "section" }, S.isApp ? t("Remote access") : t("Security")),
|
||||
@@ -1508,12 +1612,16 @@ function render() {
|
||||
else if (d.status !== "online" || !d.state)
|
||||
content = h("div", { class: "empty" }, h("div", { class: "spinner" + (["loading", "connecting"].includes(d.status) ? "" : " off") }),
|
||||
d.status === "loading" ? t("Loading the configuration from the DSP…")
|
||||
: d.status === "connecting" ? t("Connecting to {where}…", { where: where(d) }) : t("Not connected."));
|
||||
: d.status === "connecting" ? t("Connecting to {where}…", { where: where(d) })
|
||||
: d.status === "locked" ? h("div", {}, h("p", {}, t("This DSP is locked with a code.")),
|
||||
h("button", { class: "on", onclick: () => unlockDialog(d) }, t("Enter code")))
|
||||
: S.demo.enabled && !d.demo ? t("Disconnected while demo mode is on") : t("Not connected."));
|
||||
else content = ({ mixer: viewMixer, channel: viewChannel, routing: viewRouting, link: viewLink, limiter: viewLimiter }[S.view] || viewMixer)(d);
|
||||
main.replaceChildren(...[content].flat().filter(Boolean));
|
||||
main.querySelectorAll(H_SCROLL).forEach((e, i) => { if (xs[i]) e.scrollLeft = xs[i]; });
|
||||
window.scrollTo(0, y);
|
||||
collectMeters();
|
||||
if (d) maybeAskUnlock(d);
|
||||
}
|
||||
// flush deferred renders once a text field loses focus
|
||||
main.addEventListener("focusout", () => setTimeout(() => {
|
||||
@@ -1596,6 +1704,9 @@ function connectEvents() {
|
||||
case "hello":
|
||||
setDevices(ev.devices);
|
||||
if (ev.limiter) S.lim = ev.limiter;
|
||||
if (ev.demo) S.demo = ev.demo;
|
||||
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;
|
||||
render(); break;
|
||||
case "device":
|
||||
@@ -1610,8 +1721,13 @@ function connectEvents() {
|
||||
if (!d) break;
|
||||
Object.assign(d, { status: ev.status, error: ev.error, info: ev.info });
|
||||
if (ev.status !== "online") render(); else renderTabs();
|
||||
maybeAskUnlock(d);
|
||||
break;
|
||||
}
|
||||
case "demo":
|
||||
S.demo = ev.data;
|
||||
if (!S.demo.enabled && S.cur === "demo") S.cur = S.order.find(id => id !== "demo") || null;
|
||||
render(); break;
|
||||
case "param": {
|
||||
const d = S.devices[ev.device];
|
||||
if (!d || !d.state) break;
|
||||
|
||||
Reference in new issue
Block a user