diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-16 17:38:23 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-16 17:38:23 +0100 |
| commit | df7b5062118467dc02d3baade9a6b74390c050ba (patch) | |
| tree | 8627ca013e237c3494d4b13bea97a3a4ba6fe651 /static/modules | |
| parent | aaf950fa5461d7879ca28371f1c788f4daaaaed2 (diff) | |
| download | deck-it-df7b5062118467dc02d3baade9a6b74390c050ba.tar.gz deck-it-df7b5062118467dc02d3baade9a6b74390c050ba.zip | |
feat(xbox): console model, region, flags and installed titles
Diffstat (limited to 'static/modules')
| -rw-r--r-- | static/modules/xbox.js | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/static/modules/xbox.js b/static/modules/xbox.js index 65aa7f7..858d4c1 100644 --- a/static/modules/xbox.js +++ b/static/modules/xbox.js @@ -97,12 +97,39 @@ function presenceLine(st) { return p.last_seen ? `Last seen ${ago(p.last_seen.when)} · ${p.last_seen.title ?? ""}` : (p.state ?? ""); } -function consoleCard(c) { +// "XboxSeriesX" -> "Xbox Series X" +const model = (t) => (t ?? "").replace(/([a-z])([A-Z])/g, "$1 $2"); +// The installed list stays open across redraws once opened. +let appsOpen = false; + +function appsList(apps) { + const box = h("details", "xb-apps"); + box.open = appsOpen; + box.ontoggle = () => { appsOpen = box.open; }; + const total = apps.reduce((n, a) => n + a.size, 0); + box.append(h("summary", "xb-section", `Installed · ${apps.length} · ${gb(total)}`)); + for (const a of apps) { + const sub = [a.version != null ? `v${a.version}` : null, a.updated ? `updated ${ago(a.updated)}` : null, + a.last ? `played ${ago(a.last)}` : null].filter(Boolean).join(" · "); + const r = h("div", `xb-app${a.game ? " game" : ""}`); + const text = h("div", "xb-rtext"); + text.append(h("div", "xb-rtitle", a.name ?? ""), h("div", "xb-rsub", sub)); + r.append(text, h("span", "xb-rside num", gb(a.size))); + box.append(r); + } + return box; +} + +function consoleCard(c, apps) { const on = c.power === "On"; const card = h("div", "xb-card xb-console"); const head = h("div", "xb-chead"); const [label, cls] = POWER[c.power] ?? [c.power ?? "?", ""]; - head.append(h("i", "nf xb-glyph", G.xbox), h("span", "xb-cname", c.name), h("span", `xb-pill ${cls}`, label)); + const names = h("div", "xb-cnames"); + const line = h("div", "xb-cline"); + line.append(h("span", "xb-cname", c.name), h("span", `xb-pill ${cls}`, label)); + names.append(line, h("div", "xb-cmodel", [model(c.type), c.region].filter(Boolean).join(" · "))); + head.append(h("i", "nf xb-glyph", G.xbox), names); // Tap wakes, hold turns off: a stray touch must not switch a game off. const power = h("button", `ib hold xb-power${on ? " on" : ""}`, G.power); power.classList.add("nf"); @@ -130,6 +157,12 @@ function consoleCard(c) { } card.append(media); } + const flags = h("div", "xb-flags"); + for (const [on_, text] of [[c.remote, "Remote"], [c.streaming, "Streaming"]]) { + if (on_ != null) flags.append(h("span", `xb-flag${on_ ? " on" : ""}`, `${text} ${on_ ? "on" : "off"}`)); + } + card.append(flags); + if (apps?.length) card.append(appsList(apps)); card.append(h("div", "xb-err")); return card; } @@ -212,7 +245,7 @@ function render(box, st) { if (st.stale) box.append(h("div", "xb-stale", "Xbox Live is not answering; this is the last data.")); const top = h("div", "xb-top"); if (st.playing) top.append(nowPlaying(st)); - for (const c of st.consoles ?? []) top.append(consoleCard(c)); + for (const c of st.consoles ?? []) top.append(consoleCard(c, st.apps?.[c.id])); if (!st.consoles?.length && st.reason?.startsWith("consoles")) { top.append(h("div", "xb-stale", "Console control is unavailable: Xbox Live refused the console list.")); } |
