// deck-it - the Dashboard: one fixed screen // Copyright (C) 2026 Danilo M. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // The Dashboard tab: a top band of chips, music and spending always on, a // row of chips for one to three busy modules, each opening its full slot, // and the Vikunja tasks due now, only while there are some. // The page keeps the trend history; the modules' APIs are the existing ones. import { offline } from "./offline.js"; import { HOLD_MS, buzz } from "./hold.js"; export const HISTORY = 120; // trend samples: two minutes at 1 s const RUNNING = { k1c: "K1C", sbbuilder: "build", obs: "OBS" }; // the running row's order and chip labels const G = { cpu: "", mem: "\u{f035b}", gpu: "\u{f08ae}", net: "\u{f04e1}", wifi: "", charging: "\u{f0084}", tux: "", clock: "", todo: "\u{f0131}" }; const BATTERY = ["", "", "", "", ""]; // Nerd Font distro logos by os-release ID. const DISTRO = { slackware: "", arch: "", debian: "", fedora: "", ubuntu: "", gentoo: "", opensuse: "", void: "", }; const SPEND = ["var(--udt-accent)", "var(--udt-blue, #89b4fa)", "var(--udt-green, #a6e3a1)"]; const OTHER = "var(--udt-surface2)"; const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`); const rate = (b) => (b >= 1048576 ? `${(b / 1048576).toFixed(1)}M` : `${Math.round((b ?? 0) / 1024)}k`); const gib = (b) => (b / 2 ** 30).toFixed(1); const money = (v) => (v == null ? "—" : `$${Number(v).toFixed(2)}`); const tok = (n) => (n >= 1e9 ? `${(n / 1e9).toFixed(1)}B` : n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n ?? 0)); const pct = (v) => (v == null ? "—" : `${Math.round(v)}%`); const short = (m) => String(m ?? "").split("/").pop(); const uptime = (s) => { const d = Math.floor(s / 86400), h = Math.floor((s % 86400) / 3600); return d ? `${d}d ${h}h` : h ? `${h}h` : `${Math.floor(s / 60)}m`; }; export function push(list, v, n = HISTORY) { list.push(v); if (list.length > n) list.shift(); return list; } // The trend over a 120x100 viewBox, the newest sample at the right edge; the // largest value reaches 12% from the top. export function line(samples, max, n = HISTORY) { const x = (i) => ((n - samples.length + i) * 120) / (n - 1); const y = (v) => 100 - Math.min(1, v / (max || 1)) * 88; return samples.map((v, i) => `${i ? "L" : "M"}${x(i)},${y(v)}`).join(" "); } // The area under line(), closed along the bottom edge. It is filled only: // stroking it would also draw the bottom and side edges. export function area(samples, max, n = HISTORY) { const l = line(samples, max, n); return l && `M${l.slice(1, l.indexOf(","))},100 L${l.slice(1)} L120,100 Z`; } // A graph's two paths: the filled area, then the stroked line over it. const graph = ([fill, stroke], samples, max) => { fill.setAttribute("d", area(samples, max)); stroke.setAttribute("d", line(samples, max)); }; // The top 3 paid models (llm.py sorts them by cost), then the rest as "other". export function spendParts(models) { const paid = (models ?? []).filter((m) => m.cost > 0); const rest = paid.slice(3).reduce((a, m) => a + m.cost, 0); return rest > 0 ? [...paid.slice(0, 3), { model: "other", cost: rest }] : paid.slice(0, 3); } export function batteryGlyph(b) { if (b?.status === "charging" || b?.status === "full") return G.charging; return BATTERY[Math.min(4, Math.max(0, Math.round((b?.level ?? 0) / 25)))]; } // A line too long for its slot slides to its end and back (deck.css .marq); // one that fits stays still. Only changed values are written, so the // animation is not restarted by every poll. function marquee(el) { if (!el.getClientRects().length) return; // not shown: nothing to measure for (const line of el.querySelectorAll(".what, .meta")) { const over = line.firstElementChild.offsetWidth - line.clientWidth; line.classList.toggle("marq", over > 0); const d = `${-Math.max(0, over)}px`; if (line.style.getPropertyValue("--d") !== d) { line.style.setProperty("--d", d); line.style.setProperty("--t", `${2 + Math.max(0, over) / 30}s`); // ~30 px/s plus the pauses } } } // A todo's due label: "overdue 2d", "today 15:00", or "reminder" when it // only has a reminder. export function dueLabel(iso, now = new Date()) { if (!iso) return "reminder"; const due = new Date(iso); if (due.toDateString() === now.toDateString() && due >= now) return `today ${due.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hourCycle: "h23" })}`; const h = (now - due) / 3600000; return h < 24 ? `overdue ${Math.max(1, Math.round(h))}h` : `overdue ${Math.floor(h / 24)}d`; } // Tap, hold, or swipe left to right on one element. A swipe past a third // of its width fires; a shorter one springs back. Moving cancels the hold. function gestures(el, { tap, hold, swipe }) { let x0 = null, dx = 0, timer = null, sliding = false; const reset = () => { clearTimeout(timer); timer = null; x0 = null; sliding = false; el.classList.remove("holding", "sliding"); }; el.addEventListener("pointerdown", (e) => { x0 = e.clientX; dx = 0; el.setPointerCapture(e.pointerId); el.classList.add("holding"); timer = setTimeout(() => { reset(); buzz(); hold(); }, HOLD_MS); }); el.addEventListener("pointermove", (e) => { if (x0 == null) return; dx = Math.max(0, e.clientX - x0); if (!sliding && Math.abs(e.clientX - x0) > 12) { clearTimeout(timer); timer = null; sliding = true; el.classList.remove("holding"); el.classList.add("sliding"); } if (sliding) el.style.transform = `translateX(${dx}px)`; }); el.addEventListener("pointerup", () => { const wasTap = timer != null, wasSwipe = sliding && dx > el.offsetWidth / 3; reset(); if (wasSwipe) { el.style.transform = "translateX(110%)"; swipe(); } else el.style.transform = ""; if (wasTap) tap(); }); el.addEventListener("pointercancel", () => { reset(); el.style.transform = ""; }); } const SKELETON = `
|${G.tux} |${G.clock} |
${G.cpu}
${G.mem}
${G.gpu}
${G.net}
context
5h
7d
${G.wifi}
`; export default { // names: the enabled modules; poll(name, seconds, update) and open(tab) // come from app.js. mount(section, names, { poll, open }) { const on = new Set(names); const root = document.createElement("div"); root.className = "dash"; root.innerHTML = SKELETON; section.append(root); const $ = (s) => root.querySelector(s); const chip = (sel, v, s, fill, warn) => { const c = $(sel); c.querySelector(".v").textContent = v; if (s != null) c.querySelector(".s").textContent = s; if (fill != null) c.querySelector(".fill").style.width = `${Math.max(0, Math.min(100, fill))}%`; c.classList.toggle("hot", Boolean(warn)); }; // A disabled module's parts are left out. $(".dash-id").hidden = !on.has("stats"); $(".chips.sys").hidden = !on.has("stats"); for (const c of [".c-ctx", ".c-5h", ".c-7d"]) $(c).hidden = !on.has("llm"); $(".dash-spend").hidden = !on.has("llm"); $(".c-bat").hidden = $(".c-wifi").hidden = !on.has("tablet"); $(".dash-music").hidden = !on.has("music"); const hist = { cpu: [], gpu: [], down: [], up: [] }; if (on.has("stats")) poll("stats", 1, (st) => { $(".logo").textContent = DISTRO[st.os?.id] ?? G.tux; $(".os").textContent = st.os?.name ?? ""; $(".codename").textContent = st.os?.codename ? `-${st.os.codename}` : ""; $(".codename").hidden = !st.os?.codename; $(".kernel").textContent = st.os?.kernel ?? ""; $(".up").textContent = uptime(st.uptime); for (const e of root.querySelectorAll(".upd")) e.hidden = st.updates == null; $(".n-upd").textContent = `${st.updates} update${st.updates === 1 ? "" : "s"} available`; push(hist.cpu, st.cpu); push(hist.down, st.net.down); push(hist.up, st.net.up); $(".c-cpu .n").textContent = st.cpuName ?? ""; graph($(".c-cpu").querySelectorAll("path"), hist.cpu, Math.max(25, ...hist.cpu)); chip(".c-cpu", `${st.cpu}%`, st.cpuTemp != null ? `${st.cpuTemp}°C` : "", null, st.cpuTemp >= 85); chip(".c-mem", gib(st.memUsed * 1024), `/ ${Math.round(st.memTotal / 1048576)} GiB`, (100 * st.memUsed) / st.memTotal); const g = st.gpu; $(".c-gpu").hidden = !g; if (g) { $(".c-gpu .n").textContent = g.name ?? ""; // Like the CPU chip: usage on a trend, temperature beside it. VRAM // and fan are on keystone's performance page. Without usage (an // older kernel) the temperature takes the big value. if (g.util != null) { push(hist.gpu, g.util); graph($(".c-gpu").querySelectorAll("path"), hist.gpu, Math.max(25, ...hist.gpu)); } const t = g.temp != null ? `${g.temp}°C` : "—"; chip(".c-gpu", g.util != null ? `${g.util}%` : t, g.util != null ? t : "", null, g.temp >= 85); } const max = Math.max(1, ...hist.down, ...hist.up); const net = [...$(".c-net").querySelectorAll("path")]; graph(net.slice(0, 2), hist.down, max); graph(net.slice(2), hist.up, max); chip(".c-net", `↓${rate(st.net.down)} ↑${rate(st.net.up)}`); }); const program = (title, p, brand) => { const h3 = `

${brand ? `` : ""}${esc(title)}

`; const model = `${esc(p.model ? short(p.model) : "—")}`; if (!(p.cost > 0)) { // local or free models: tokens, not dollars return `
${h3}${model} session${tok(p.session_tokens)} total${tok(p.tokens)}
`; } const parts = spendParts(p.models); const total = parts.reduce((a, m) => a + m.cost, 0); const color = (m, i) => (m.model === "other" ? OTHER : SPEND[i]); return `
${h3}${model}
session
${money(p.session_cost)}
${tok(p.session_tokens)} · ${p.session_calls ?? 0} calls
total
${money(p.cost)}
${tok(p.tokens)} · ${p.calls ?? 0} calls
${parts.map((m, i) => ``).join("")}
${parts.map((m, i) => `${esc(short(m.model))} ${money(m.cost)}`).join("")}
`; }; if (on.has("llm")) poll("llm", 5, (st) => { const spend = $(".dash-spend"); if (st.offline) { offline(spend, { icon: "/logos/claude.svg", title: "Usage dashboard is off", detail: "Start llm-cost-dashboard and the spending appears here." }); for (const c of [".c-ctx", ".c-5h", ".c-7d"]) chip(c, "—", null, 0); return; } const c = st.claude ?? {}; chip(".c-ctx", pct(c.context_pct), null, c.context_pct, c.context_pct >= 80); chip(".c-5h", pct(c.five_hour_pct), null, c.five_hour_pct, c.five_hour_pct >= 80); chip(".c-7d", pct(c.seven_day_pct), null, c.seven_day_pct, c.seven_day_pct >= 80); spend._offline = null; spend.innerHTML = program("opencode", st.opencode ?? {}, "opencode") + program("Local Agent", st.assistant ?? {}); }); if (on.has("tablet")) poll("tablet", 10, (t) => { const b = t.battery ?? {}, w = t.wifi ?? {}; const charging = b.status === "charging" || b.status === "full"; $(".c-bat .ic").textContent = batteryGlyph(b); chip(".c-bat", b.level != null ? `${b.level}%` : "—", null, b.level, b.level < 20 && !charging); $(".c-bat").classList.toggle("charging", b.status === "charging"); chip(".c-wifi", w.rssi != null ? `${w.rssi} dBm` : "—", w.band ?? "", w.rssi == null ? 0 : 2 * (w.rssi + 100)); // -100 dBm empty, -50 full }); if (on.has("music")) import("./modules/music.js").then(({ default: music, pickGame }) => { const el = $(".dash-music"); music.mount(el); // The card shows a running game (PC or Xbox) instead of the music. const last = { music: {}, games: null, xbox: null }; const draw = () => music.update(last.music, el, pickGame(last.games, last.xbox)); poll("music", music.interval ?? 2, (st) => { last.music = st; draw(); }); if (on.has("games")) poll("games", 5, (st) => { last.games = st; draw(); }); if (on.has("xbox")) poll("xbox", 30, (st) => { last.xbox = st; draw(); }); }); // Vikunja tasks due now: tap opens one on the PC, hold marks it done, // a swipe right snoozes it 30 min. Redrawn only when the list changes, // and never under a finger. const todo = $(".dash-todo"); const drawTodo = (st) => { const key = JSON.stringify(st); if (todo._key === key || todo.querySelector(".holding, .sliding")) return; todo._key = key; const tasks = st.tasks ?? []; todo.hidden = !tasks.length && !st.error; todo.textContent = ""; if (st.error) { todo.innerHTML = `
Vikunja unreachable
`; todo.firstChild.title = st.error; return; } const act = async (name, id, line) => { let ok = false; try { ok = (await fetch(`/api/todo/${name}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id }) })).ok; if (ok && name !== "open") drawTodo(await (await fetch("/api/todo")).json()); } catch {} if (!ok) { // back in place, red for a moment line.classList.remove("gone"); line.style.transform = ""; line.classList.add("fail"); setTimeout(() => line.classList.remove("fail"), 1500); } }; for (const t of tasks.slice(0, 3)) { const line = document.createElement("div"); line.className = "td"; line.innerHTML = ``; line.querySelector(".nf").textContent = G.todo; line.querySelector(".tt").textContent = t.title; const due = dueLabel(t.due); line.querySelector(".due").textContent = due; line.classList.toggle("late", due.startsWith("overdue")); gestures(line, { tap: () => act("open", t.id, line), hold: () => { line.classList.add("gone"); act("done", t.id, line); }, swipe: () => act("snooze", t.id, line) }); todo.append(line); } if (tasks.length > 3) { const more = document.createElement("div"); more.className = "td more"; more.textContent = `+${tasks.length - 3}`; todo.append(more); } }; if (on.has("todo")) poll("todo", 10, drawTodo); // The running row: a chip per module, created now in RUNNING order and // shown while it is busy. A tap opens its full slot, and the module's // detail(state, el) when it has one, centred over the page; a tap // outside closes it (closedby="any", Chrome 134+) without reaching what is // under it, a tap inside opens the module's tab. const row = $(".dash-running"); for (const name of Object.keys(RUNNING).filter((n) => on.has(n))) { const chip = document.createElement("div"); chip.className = `chip run-${name}`; chip.hidden = true; chip.innerHTML = ``; chip.querySelector(".k").textContent = RUNNING[name]; const pop = document.createElement("dialog"); pop.setAttribute("closedby", "any"); pop.className = "card run-pop"; pop.innerHTML = `
`; const [slotEl, detailEl] = pop.children; row.append(chip, pop); chip.addEventListener("click", () => { pop.showModal(); marquee(slotEl); }); import(`./modules/${name}.js`).then((mod) => { if (!mod.busy || !mod.slot) return; const tab = mod.default?.tab; pop.addEventListener("click", (e) => { if (tab && !e.target.closest("button")) { pop.close(); open(tab); } }); // ponytail: the K1C and OBS tabs poll the same API; two polls a second, one cache if it matters. poll(name, mod.interval ?? mod.default?.interval ?? 2, (st) => { chip.hidden = !mod.busy(st); if (chip.hidden) { pop.close(); return; } mod.slot(st, slotEl); mod.detail?.(st, detailEl); // ponytail: the chip mirrors the slot's icon, value and bar, so a // module draws one slot; a chip(state) export if one ever needs more. const bar = slotEl.querySelector(".bar"); chip.querySelector(".ic").textContent = slotEl.querySelector(".sic")?.textContent ?? ""; chip.querySelector(".v").textContent = slotEl.querySelector(".pct")?.textContent ?? ""; chip.querySelector(".fill").style.width = bar?.querySelector("i").style.width ?? ""; chip.classList.toggle("busy", !!bar?.classList.contains("busy")); chip.classList.toggle("rec", !!slotEl.querySelector(".sic.rec")); row.hidden = !row.querySelector(".chip:not([hidden])"); if (pop.open) marquee(slotEl); }); }); } }, };