From 46a164e797c0fd77ee67e2bae9bec5c02ad1de2d Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 9 Nov 2026 18:26:00 +0100 Subject: fix: add stats, music and windows panels --- static/app.js | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'static/app.js') diff --git a/static/app.js b/static/app.js index 7a9ff40..ed19c60 100644 --- a/static/app.js +++ b/static/app.js @@ -3,31 +3,34 @@ // mount(el), update(state, el)}. A missing or broken panel is skipped. const grid = document.getElementById("grid"); +const refreshers = []; async function mountModule(name) { - let panel; try { - panel = (await import(`./modules/${name}.js`)).default; + const panel = (await import(`./modules/${name}.js`)).default; + const el = document.createElement("section"); + el.className = "panel"; + el.dataset.module = name; + const title = document.createElement("h2"); + title.textContent = panel.title ?? name; + el.append(title); + grid.append(el); + panel.mount?.(el); + + const poll = async () => { + try { + const r = await fetch(`/api/${name}`); + if (r.ok) panel.update?.(await r.json(), el); + } catch { + // keep the last state; the next tick retries + } + }; + refreshers.push(poll); + await poll(); + setInterval(poll, (panel.interval ?? 1) * 1000); } catch { - return; + // a broken panel must not take down the rest of the dashboard } - const el = document.createElement("section"); - el.className = "panel"; - el.dataset.module = name; - el.innerHTML = `

${panel.title ?? name}

`; - grid.append(el); - panel.mount?.(el); - - const poll = async () => { - try { - const r = await fetch(`/api/${name}`); - if (r.ok) panel.update?.(await r.json(), el); - } catch { - // keep the last state; the next tick retries - } - }; - await poll(); - setInterval(poll, (panel.interval ?? 1) * 1000); } async function boot() { @@ -36,4 +39,8 @@ async function boot() { for (const { name } of await r.json()) await mountModule(name); } +document.addEventListener("visibilitychange", () => { + if (document.visibilityState === "visible") refreshers.forEach((fn) => fn()); +}); + boot(); -- cgit v1.2.3