diff options
Diffstat (limited to 'static/modules/xbox.js')
| -rw-r--r-- | static/modules/xbox.js | 20 |
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. |
