diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-16 17:17:52 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-16 17:17:52 +0100 |
| commit | d4b1130931a430395b4172c28130693cc05c77c0 (patch) | |
| tree | f7532919ef301cf338e3712a9d98860610039751 | |
| parent | 766251ed6dc1858b544aa1c50de72b93d10b84d4 (diff) | |
| download | deck-it-d4b1130931a430395b4172c28130693cc05c77c0.tar.gz deck-it-d4b1130931a430395b4172c28130693cc05c77c0.zip | |
feat(xbox): switch to the Xbox tab once per game session
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | static/app.js | 2 | ||||
| -rw-r--r-- | static/modules/xbox.js | 28 | ||||
| -rw-r--r-- | tests/test_xbox.mjs | 29 |
3 files changed, 59 insertions, 0 deletions
diff --git a/static/app.js b/static/app.js index 5d1688a..bb30814 100644 --- a/static/app.js +++ b/static/app.js @@ -89,10 +89,12 @@ function showTab(name) { // A panel's peek(state) gives seconds when something new turned up: its tab // comes forward that long, then the page goes back, unless touched first. +// Infinity brings it forward to stay, as a page change by hand would. let peek = null; // {back, timer} while a tab is shown on its own function peekTab(name, seconds) { const now = Object.keys(tabs).find((n) => !tabs[n].section.hidden); if (now === name && !peek) return; // already there by choice + if (!Number.isFinite(seconds)) return showTab(name); const back = peek?.back ?? now; showTab(name); peek = { back, timer: setTimeout(() => showTab(back), seconds * 1000) }; diff --git a/static/modules/xbox.js b/static/modules/xbox.js new file mode 100644 index 0000000..3350f52 --- /dev/null +++ b/static/modules/xbox.js @@ -0,0 +1,28 @@ +// deck-it - the Xbox tab: Xbox Live profile, games, friends and the console +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +const SESSION_KEY = "deckit-xbox-session"; + +// A game session on the Xbox brings this tab forward once and leaves it +// there (app.js reads Infinity as "stay"). The session is remembered, so a +// reload, or leaving the tab, does not bring it back until the next one. +export function sessionPeek(st, store = globalThis.localStorage) { + if (!st.session || store.getItem(SESSION_KEY) === String(st.session)) return 0; + store.setItem(SESSION_KEY, st.session); + return Infinity; +} + +export default { title: "Xbox", tab: "Xbox", interval: 5, peek: (st) => sessionPeek(st) }; diff --git a/tests/test_xbox.mjs b/tests/test_xbox.mjs new file mode 100644 index 0000000..36a5e31 --- /dev/null +++ b/tests/test_xbox.mjs @@ -0,0 +1,29 @@ +// deck-it - checks for the Xbox tab's session switch +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import assert from "node:assert/strict"; + +const { sessionPeek } = await import("../static/modules/xbox.js"); + +const store = new Map(); +const fake = { getItem: (k) => store.get(k) ?? null, setItem: (k, v) => store.set(k, String(v)) }; + +assert.equal(sessionPeek({ session: null }, fake), 0); +assert.equal(sessionPeek({ session: 100 }, fake), Infinity); // a new session switches once +assert.equal(sessionPeek({ session: 100 }, fake), 0); // then never again +assert.equal(sessionPeek({ session: null }, fake), 0); +assert.equal(sessionPeek({ session: 200 }, fake), Infinity); // the next session does +console.log("xbox ok"); |
