diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-09 19:23:56 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-09 19:23:56 +0100 |
| commit | c04cfb4179068144d47c0fe64fc08344dd605457 (patch) | |
| tree | fbc7ac0ac7710329f58a2230a2dd79ffc52b602c /static/modules/stats.js | |
| parent | 04bd03db72c7165debb79d1858f39121757ca358 (diff) | |
| download | deck-it-c04cfb4179068144d47c0fe64fc08344dd605457.tar.gz deck-it-c04cfb4179068144d47c0fe64fc08344dd605457.zip | |
feat: tablet-first dashboard tiles and match the Hyprland border speed
Diffstat (limited to 'static/modules/stats.js')
| -rw-r--r-- | static/modules/stats.js | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/static/modules/stats.js b/static/modules/stats.js index a119c6c..16dffd2 100644 --- a/static/modules/stats.js +++ b/static/modules/stats.js @@ -1,36 +1,26 @@ -const gb = (kb) => (kb / 1048576).toFixed(1); -const rate = (b) => (b >= 1048576 ? `${(b / 1048576).toFixed(1)} MB/s` : `${Math.round(b / 1024)} KB/s`); +const gib = (kb) => (kb / 1048576).toFixed(1); +const bytes = (b) => (b == null ? "?" : (b / 1073741824).toFixed(1)); +const rate = (b) => (b >= 1048576 ? `${(b / 1048576).toFixed(1)}M` : `${Math.round(b / 1024)}k`); const uptime = (s) => { const d = Math.floor(s / 86400); const h = Math.floor((s % 86400) / 3600); - const m = Math.floor((s % 3600) / 60); - return d ? `${d}d ${h}h` : `${h}h ${m}m`; -}; -const gib = (b) => (b / 1073741824).toFixed(1); -const gpu = (g) => { - if (!g) return "—"; - if (g.asleep) return `${g.name} (asleep)`; - const parts = [g.name]; - if (g.util != null) parts.push(`${g.util}%`); - if (g.temp != null) parts.push(`${g.temp}°C`); - if (g.fan != null) parts.push(`${g.fan} rpm`); - if (g.memUsed != null) { - parts.push(g.memTotal ? `${gib(g.memUsed)} / ${gib(g.memTotal)} GiB` : `${gib(g.memUsed)} GiB`); - } - return parts.join(" · "); + return d ? `${d}d ${h}h` : `${h}h`; }; -function row(label, value) { - const div = document.createElement("div"); - div.className = "row"; - const name = document.createElement("span"); - name.className = "muted"; - name.textContent = label; - const val = document.createElement("span"); - val.className = "num"; - val.textContent = value; - div.append(name, val); - return div; +function tile(label, value, sub) { + const d = document.createElement("div"); + d.className = "mtile"; + const l = document.createElement("span"); + l.className = "mlabel"; + l.textContent = label; + const v = document.createElement("span"); + v.className = "mvalue num"; + v.textContent = value; + const s = document.createElement("span"); + s.className = "msub"; + s.textContent = sub || ""; + d.append(l, v, s); + return d; } export default { @@ -38,20 +28,23 @@ export default { interval: 1, mount(el) { - const box = document.createElement("div"); - box.className = "stats"; - el.append(box); + el.innerHTML = `<div class="stats"></div>`; }, update(st, el) { const box = el.querySelector(".stats"); box.textContent = ""; + const g = st.gpu; box.append( - row("CPU", `${st.cpu}%${st.cpuTemp != null ? ` · ${st.cpuTemp}°C` : ""}`), - row("Memory", `${gb(st.memUsed)} / ${gb(st.memTotal)} GiB`), - row("GPU", gpu(st.gpu)), - row("Network", `↓ ${rate(st.net.down)} ↑ ${rate(st.net.up)}`), - row("Uptime", uptime(st.uptime)), + tile("CPU", `${st.cpu}%`, st.cpuTemp != null ? `${st.cpuTemp}°C` : "—"), + tile("Memory", gib(st.memUsed), `/ ${gib(st.memTotal)} GiB`), + tile("GPU", g?.temp != null ? `${g.temp}°` : "—", + g ? `${bytes(g.memUsed)} / ${bytes(g.memTotal)} GiB` : "no GPU"), + tile("Network", `↓${rate(st.net.down)}`, `↑${rate(st.net.up)}`), ); + const foot = document.createElement("div"); + foot.className = "mfoot"; + foot.textContent = `up ${uptime(st.uptime)}`; + box.append(foot); }, }; |
