From df7b5062118467dc02d3baade9a6b74390c050ba Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 16 Nov 2026 17:38:23 +0100 Subject: feat(xbox): console model, region, flags and installed titles --- AGENTS.md | 7 +++++-- deckit/modules/xbox.py | 16 +++++++++++++++- static/deck.css | 15 ++++++++++++++- static/modules/xbox.js | 39 ++++++++++++++++++++++++++++++++++++--- tests/test_xbox.py | 13 +++++++++++++ 5 files changed, 83 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9733b87..dee3791 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -98,8 +98,11 @@ Keep the server dependency-free apart from that one package. tab, the refresh token in `~/.config/deck-it/xbox-token.json` (0600), the MS → user token → XSTS chain in memory. A thread reads presence and the consoles (`xccs`) every 30s, profile, recent titles (titlehub, minutes from - userstats), the last achievements and friends every 10 min and on a title - change; an endpoint that refuses keeps its last data. A foreground title + userstats), the last achievements, friends and each console's installed + titles (`xccs` installedApps) every 10 min and on a title change; an + endpoint that refuses keeps its last data. Xbox Live has no system + software version. `_http` sends `User-Agent: deck-it`: xccs's gateway + answers 403 to urllib's default. A foreground title that titlehub calls a Game is `playing`: `$XDG_RUNTIME_DIR/status.xbox` gets 1 (keystone ORs it into presentation) and `xbox.js`'s `peek` returns `Infinity` once per `session`, which `app.js` reads as "show and stay". diff --git a/deckit/modules/xbox.py b/deckit/modules/xbox.py index 16cd389..7b3da3d 100644 --- a/deckit/modules/xbox.py +++ b/deckit/modules/xbox.py @@ -141,11 +141,21 @@ def summarize_profile(r: dict) -> dict: def summarize_consoles(r: dict) -> list: return [{"id": c["id"], "name": c.get("name"), "type": c.get("consoleType"), "power": c.get("powerState"), + "region": c.get("region"), "remote": c.get("remoteManagementEnabled"), + "streaming": c.get("consoleStreamingEnabled"), "storage": [{"name": d.get("storageDeviceName"), "free": d.get("freeSpaceBytes"), "total": d.get("totalSpaceBytes")} for d in c.get("storageDevices") or []]} for c in r.get("result") or []] +def summarize_apps(r: dict) -> list: + """A console's installed titles, biggest first.""" + apps = [{"name": a.get("name"), "game": a.get("contentType") == "Game", "size": a.get("sizeInBytes") or 0, + "version": a.get("version"), "updated": a.get("updateTime") or a.get("installTime"), + "last": a.get("lastActiveTime")} for a in r.get("result") or []] + return sorted(apps, key=lambda a: -a["size"]) + + def minutes_played(r: dict) -> dict: """title id -> minutes, from a userstats batch of MinutesPlayed.""" out = {} @@ -387,6 +397,10 @@ class Xbox: "titles": titles, "achievements": lambda: summarize_achievements(self.api(ACHIEVEMENTS.format(xuid), 2)), "friends": lambda: summarize_friends(self.api(FRIENDS, 7)), + # console id -> installed titles + "apps": lambda: {c["id"]: summarize_apps(self.api( + XCCS + "/lists/installedApps?deviceId=" + urllib.parse.quote(c["id"]), 4, extra=SG)) + for c in self.data.get("consoles") or []}, } for key, read in parts.items(): try: @@ -394,7 +408,7 @@ class Xbox: except HttpError as e: if e.status == 401: raise - self.data = {**self.data, key: self.data.get(key) or ([] if key != "profile" else None)} + self.data = {**self.data, key: self.data.get(key) or {"profile": None, "apps": {}}.get(key, [])} self.reason = f"{key}: {e}" def type_of(self, tid: str): diff --git a/static/deck.css b/static/deck.css index d5aef6b..6681c3e 100644 --- a/static/deck.css +++ b/static/deck.css @@ -897,7 +897,20 @@ dialog.vm-sheet::backdrop { background: color-mix(in srgb, var(--udt-crust) 55%, .xbox .xb-console { display: flex; flex-direction: column; gap: 10px; } .xbox .xb-chead { display: flex; align-items: center; gap: 10px; } .xbox .xb-glyph { font-size: 1.8rem; color: var(--udt-green); } -.xbox .xb-cname { flex: 1; font-size: 1.15rem; font-weight: 600; } +.xbox .xb-cnames { flex: 1; min-width: 0; } +.xbox .xb-cline { display: flex; align-items: center; gap: 10px; min-width: 0; } +.xbox .xb-cname { font-size: 1.15rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.xbox .xb-cline .xb-pill { flex: none; } +.xbox .xb-cmodel { color: var(--udt-subtext0); font-size: 0.857rem; } +.xbox .xb-flags { display: flex; flex-wrap: wrap; gap: 8px; } +.xbox .xb-flag { padding: 2px 10px; border-radius: 999px; font-size: 0.857rem; + border: 1px solid var(--udt-surface1); color: var(--udt-subtext0); } +.xbox .xb-flag.on { border-color: var(--udt-green); color: var(--udt-green); } +.xbox .xb-apps { display: flex; flex-direction: column; gap: 8px; } +.xbox .xb-apps > summary { cursor: pointer; min-height: 32px; } +.xbox .xb-app { display: flex; align-items: center; gap: 10px; padding: 4px 0; } +.xbox .xb-app.game .xb-rtitle { color: var(--udt-text); } +.xbox .xb-app:not(.game) .xb-rtitle { color: var(--udt-subtext1); } .xbox .xb-pill { padding: 4px 12px; border-radius: 999px; background: var(--udt-surface1); font-weight: 600; } .xbox .xb-pill.good { background: var(--udt-green); color: var(--udt-crust); } .xbox .xb-pill.warn { background: var(--udt-yellow); color: var(--udt-crust); } 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.")); } diff --git a/tests/test_xbox.py b/tests/test_xbox.py index 1b73a2d..f70aa6f 100644 --- a/tests/test_xbox.py +++ b/tests/test_xbox.py @@ -36,6 +36,10 @@ CONSOLES = {"status": {"errorCode": "OK"}, "result": [ PROFILE = {"profileUsers": [{"id": "1", "settings": [ {"id": "Gamertag", "value": "Player"}, {"id": "GameDisplayPicRaw", "value": "https://img.example.org/p.png"}, {"id": "Gamerscore", "value": "12345"}]}]} +APPS = {"result": [ + {"name": "Small App", "contentType": "App", "sizeInBytes": 1e8, "version": 7, "installTime": "2026-10-01T00:00:00Z"}, + {"name": "Big Game", "contentType": "Game", "sizeInBytes": 9e10, "version": 12, "installTime": "2026-09-01T00:00:00Z", + "updateTime": "2026-11-10T00:00:00Z", "lastActiveTime": "2026-11-15T21:00:00Z"}]} HISTORY = {"titles": [ {"titleId": "1234", "name": "Some Game", "type": "Game", "displayImage": "https://img.example.org/c.png", "titleHistory": {"lastTimePlayed": "2026-11-16T10:00:00Z"}, @@ -76,6 +80,7 @@ class Fake: "achievements.xboxlive.com": ACHIEVEMENTS, "peoplehub": FRIENDS, "/commands": {"status": {"errorCode": "OK"}, "opId": "op"}, + "/lists/installedApps": APPS, } self.answers.update(over) @@ -167,6 +172,12 @@ class Summaries(unittest.TestCase): self.assertEqual((c["id"], c["name"], c["power"]), ("CON1", "Living room", "On")) self.assertEqual(c["storage"], [{"name": "Internal", "free": 4e11, "total": 1e12}]) + def test_apps_biggest_first(self): + a = xb.summarize_apps(APPS) + self.assertEqual([x["name"] for x in a], ["Big Game", "Small App"]) + self.assertEqual((a[0]["game"], a[0]["version"], a[0]["updated"]), (True, 12, "2026-11-10T00:00:00Z")) + self.assertEqual(a[1]["updated"], "2026-10-01T00:00:00Z") # never updated: the install time + def test_minutes_and_titles(self): minutes = xb.minutes_played(STATS) self.assertEqual(minutes, {"1234": 185}) @@ -240,6 +251,8 @@ class Tick(Base): self.assertEqual(st["titles"][0]["minutes"], 185) self.assertEqual(st["achievements"][0]["score"], 15) self.assertEqual(st["friends"][0]["gamertag"], "amy") + self.assertEqual(st["apps"]["CON1"][0]["name"], "Big Game") + self.assertIn("deviceId=CON1", self.fake.urls("/lists/installedApps")[0][0]) self.assertEqual(st["playing"]["name"], "Some Game") self.assertIsInstance(st["session"], int) self.assertEqual(self.status.read_text(), "1") -- cgit v1.2.3