aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules/xbox.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-16 17:54:32 +0100
committerDanilo M. <danix@danix.xyz>2026-11-16 17:54:32 +0100
commit72f0f05096cea0695a6b65c8c911c43b89b791c0 (patch)
treebd72c5c85429d7d83afab46e627fccc4d1386d21 /static/modules/xbox.js
parent903a4527a9ed8802800c0fd0c09123ef3cde4c55 (diff)
downloaddeck-it-72f0f05096cea0695a6b65c8c911c43b89b791c0.tar.gz
deck-it-72f0f05096cea0695a6b65c8c911c43b89b791c0.zip
fix(xbox): follow a power change quickly
Diffstat (limited to 'static/modules/xbox.js')
-rw-r--r--static/modules/xbox.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/static/modules/xbox.js b/static/modules/xbox.js
index b6b1c45..ddfb252 100644
--- a/static/modules/xbox.js
+++ b/static/modules/xbox.js
@@ -80,11 +80,22 @@ async function post(action, body) {
if (!r.ok) throw new Error((await r.text()) || `${action} failed`);
}
+// Xbox Live reports a power change some seconds late: until it does (30s at
+// most), the pill says what was asked. console id -> {label, from, until}
+const pending = {};
+const PENDING = { wake: "Waking…", off: "Turning off…" };
+
async function send(action, id, card) {
const err = card.querySelector(".xb-err");
err.textContent = "";
try {
await post(action, { console: id });
+ if (PENDING[action]) {
+ const pill = card.querySelector(".xb-pill");
+ pending[id] = { label: PENDING[action], from: pill.dataset.power, until: Date.now() + 30000 };
+ pill.textContent = PENDING[action];
+ pill.className = "xb-pill warn";
+ }
} catch (e) {
err.textContent = e.message;
}
@@ -104,10 +115,15 @@ 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 ?? "?", ""];
+ const p = pending[c.id];
+ const waiting = p && p.from === c.power && Date.now() < p.until;
+ if (!waiting) delete pending[c.id];
+ const [label, cls] = waiting ? [p.label, "warn"] : POWER[c.power] ?? [c.power ?? "?", ""];
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));
+ const pill = h("span", `xb-pill ${cls}`, label);
+ pill.dataset.power = c.power ?? "";
+ line.append(h("span", "xb-cname", c.name), pill);
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.