diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-09 18:26:00 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-09 18:26:00 +0100 |
| commit | 46a164e797c0fd77ee67e2bae9bec5c02ad1de2d (patch) | |
| tree | 566bb56c30b85a37f15b96a529ff252d69acb867 /static/app.js | |
| parent | 7f99167f0b6a3c83bf77e20bc5e03942b901fb71 (diff) | |
| download | deck-it-46a164e797c0fd77ee67e2bae9bec5c02ad1de2d.tar.gz deck-it-46a164e797c0fd77ee67e2bae9bec5c02ad1de2d.zip | |
fix: add stats, music and windows panels
Diffstat (limited to 'static/app.js')
| -rw-r--r-- | static/app.js | 47 |
1 files changed, 27 insertions, 20 deletions
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 = `<h2>${panel.title ?? name}</h2>`; - 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(); |
