From db13056723c0c13fcf9ea98ed258a619f9654ab8 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 16 Nov 2026 17:24:13 +0100 Subject: fix(xbox): a redrawn hold never fires, and start clears the flag A power button rebuilt mid-hold lost its pointerup, so letting go early still turned the console off; hold.js now drops a hold whose button is no longer in the page. status.xbox is written 0 on start, in case a crash left it at 1. The "ago" texts move on each minute, and missing storage names and achievement percentages no longer print null. Co-Authored-By: Claude Opus 5.5 --- deckit/modules/xbox.py | 1 + static/hold.js | 3 ++- static/modules/xbox.js | 13 +++++++------ tests/test_xbox.py | 5 +++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/deckit/modules/xbox.py b/deckit/modules/xbox.py index 3ed7ce3..8efa426 100644 --- a/deckit/modules/xbox.py +++ b/deckit/modules/xbox.py @@ -471,6 +471,7 @@ class Xbox: self.wake.clear() def start(self): + self._set_playing(None) # a crash mid-game left status.xbox at 1 if self.client_id: threading.Thread(target=self.run, daemon=True).start() diff --git a/static/hold.js b/static/hold.js index e937a25..9f2b8da 100644 --- a/static/hold.js +++ b/static/hold.js @@ -36,7 +36,8 @@ export function hold(btn, fire, { ms = HOLD_MS, tap } = {}) { e.stopPropagation(); btn.setPointerCapture(e.pointerId); btn.classList.add("holding"); - timer = setTimeout(() => { cancel(); buzz(); fire(); }, ms); + // A button redrawn away mid-hold has lost its pointerup: drop the hold. + timer = setTimeout(() => { const live = btn.isConnected; cancel(); if (live) { buzz(); fire(); } }, ms); }); btn.addEventListener("pointerup", () => { if (timer && tap) tap(); diff --git a/static/modules/xbox.js b/static/modules/xbox.js index 7e2f075..ec4a14a 100644 --- a/static/modules/xbox.js +++ b/static/modules/xbox.js @@ -113,7 +113,7 @@ function consoleCard(c) { for (const d of c.storage ?? []) { const row = h("div", "xb-disk"); const used = d.total ? (d.total - d.free) / d.total : 0; - row.append(h("span", "", `${d.name} · ${gb(d.free)} free of ${gb(d.total)}`)); + row.append(h("span", "", `${d.name ?? ""} · ${gb(d.free)} free of ${gb(d.total)}`)); const bar = h("div", "gbar"); bar.append(h("i")); bar.firstChild.style.width = `${Math.round(used * 100)}%`; @@ -144,10 +144,10 @@ function nowPlaying(st) { h("div", "xb-nrich", g.rich ?? ""), h("div", "xb-clock num", clock(st.session))); if (t) { const a = t.achievements; - info.append(h("div", "xb-nach", `${a.score} / ${a.max} G · ${Math.round(a.pct)}%`)); + info.append(h("div", "xb-nach", `${a.score} / ${a.max} G · ${Math.round(a.pct ?? 0)}%`)); const bar = h("div", "gbar"); bar.append(h("i")); - bar.firstChild.style.width = `${a.pct}%`; + bar.firstChild.style.width = `${a.pct ?? 0}%`; info.append(bar); } card.append(info); @@ -161,7 +161,7 @@ function gameTile(t) { const a = t.achievements; const bar = h("div", "gbar"); bar.append(h("i")); - bar.firstChild.style.width = `${a.pct}%`; + bar.firstChild.style.width = `${a.pct ?? 0}%`; tile.append(bar, h("div", "xb-gmeta", [`${a.score}/${a.max} G`, hours(t.minutes)].filter(Boolean).join(" · "))); } else { tile.append(h("div", "xb-gmeta", ago(t.last))); @@ -261,8 +261,9 @@ export default { } // Drawn again only when the data changed: a redraw restarts the images // and would cut a held power button short. - // ponytail: a hold across a 30s data change still restarts; key per card if it bites. - const key = JSON.stringify(st); + // ponytail: a hold across a data change is dropped (hold.js); key per card if it bites. + // The minute is in the key so the "ago" texts move on with idle data. + const key = JSON.stringify(st) + Math.floor(Date.now() / 60000); if (on._key !== key) { on._key = key; if (st.signed_in === false) signIn(on, st); diff --git a/tests/test_xbox.py b/tests/test_xbox.py index 8a14bb6..748d0ca 100644 --- a/tests/test_xbox.py +++ b/tests/test_xbox.py @@ -338,6 +338,11 @@ class Tick(Base): x._set_playing({"id": "1234", "name": "Some Game"}) self.assertEqual(self.status.read_text(), "0") + def test_start_clears_a_flag_left_by_a_crash(self): + self.status.write_text("1") + self.xbox(client_id="").start() + self.assertEqual(self.status.read_text(), "0") + def test_stop_writes_zero(self): x = self.xbox() x.tick() -- cgit v1.2.3