1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# Xbox tab design
A tab with the user's Xbox Live data (profile, presence, consoles, recent
games, achievements, friends) and the console's power and media control.
While a game runs on the Xbox the PC goes into keystone's presentation mode
and the tablet switches to the tab once.
There is no local API on a retail console: everything goes through Xbox Live,
with the user's own Azure app registration (a public client, personal
Microsoft accounts, public client flows on). Standard library only, no
`xbox-webapi`, no third-party proxy such as OpenXBL.
## Server: `deckit/modules/xbox.py`
### Auth
- `[xbox] client_id` is the Azure app's client id. Empty: `state()` is
`{offline: true, unconfigured: true}`.
- Device code flow on `login.microsoftonline.com/consumers`, scope
`XboxLive.signin offline_access`. The `login` action requests a code and
returns it; `state()` carries `{signed_in: false, login: {code, url,
expires}}` while a thread polls the token endpoint at the interval
Microsoft gives, until approved or expired.
- The refresh token is saved to `~/.config/deck-it/xbox-token.json`, mode
0600, and replaced whenever Microsoft rotates it.
- Chain: MS access token → `user.auth.xboxlive.com` (`RpsTicket` `d=<token>`)
→ `xsts.auth.xboxlive.com` (relying party `http://xboxlive.com`), giving
the XSTS token, user hash and xuid. Kept in memory; renewed before its
`NotAfter`, and once on a 401. A refresh that Microsoft rejects deletes the
file and gives `signed_in: false`.
### Reads
- Every 30s, in a thread (never on the request path):
- presence (`userpresence`): state, the title in the foreground on the
console (id, name, rich presence), last seen.
- consoles (`xccs` `lists/devices`, storage included): id, name, type,
power state (`On`, `ConnectedStandby`, `Off`), storage free and total.
- Every 10 min, and when the presence title changes:
- profile (`profile` settings): gamertag, gamerpic, gamerscore.
- recent titles (`titlehub` title history, achievement and image
decoration): name, cover, type, last played, achievements done/total,
gamerscore done/total; minutes played from `userstats` `MinutesPlayed`.
- last 10 unlocked achievements (`achievements`, ordered by unlock time):
name, description, icon, gamerscore, title, unlock time.
- friends (`peoplehub` social with presence detail): gamertag, gamerpic,
presence state and text, favourite. Online ones first.
- A network failure keeps the last state, marks it `offline` after the first
failed 30s read, and retries on the next tick.
### Playing
- Playing is the foreground title being a Game in titlehub's `type`, not an
App (YouTube, Netflix, the home screen). A title's type is looked up once
and cached.
- `state.playing` is that title, `state.session` the time playing started
(set on the not-playing to playing edge, cleared on the other).
- `$XDG_RUNTIME_DIR/status.xbox` gets `1` while playing, `0` otherwise and on
module `stop`, written atomically (temp file + rename) only on change.
### Actions
Each console action takes `{console}`, which must be an id the last state
listed, else `ModuleError`.
- `login`: start the device code flow (above).
- `wake`, `off`: power on and off through `xccs` `commands`.
- `play`, `pause`, `vol_up`, `vol_down`, `mute`: media and volume commands
through `xccs`.
The command bodies (type, command, parameters, headers) are not documented by
Microsoft; they are taken from xbox-webapi's source and checked live on the
console. A command's error message becomes the `ModuleError`, shown on the
tab.
## Panel: `static/modules/xbox.js`, tab "Xbox"
- Not configured / network down: `offline.js`'s card.
- Signed out: a "Sign in" button; then the code, large, and
`microsoft.com/devicelogin`, until signed in or expired.
- Header: gamerpic, gamertag, gamerscore, presence line.
- Console card per console: name, power pill, storage bar, power button (tap
wakes, hold turns off, through `hold.js`), and while on the media row
(play/pause, volume down/up, mute). Nerd Font glyphs.
- Now playing (while playing): cover, title, rich presence, session time, the
title's achievement progress.
- Recent games: a grid of covers with a progress bar, gamerscore and hours.
- Recent achievements and friends as lists.
- Images (gamerpics, covers, achievement icons) are loaded by the tablet
straight from Microsoft's CDN, as K1C's camera is from the printer.
- `peek(st)` returns `Infinity` once per new `st.session`; the last one seen
is kept in `localStorage`, so a reload mid-session does not switch again.
- `app.js`: `peekTab` treats a non-finite duration as "show the tab and do not
go back".
## Keystone (quickshell repo)
- `shared/Status.qml`: a `status.xbox` ModeFile, ORed into `presentation`
with `gaming`. Like `gaming`, it is not a mode `statusctl` exposes.
- `Modules.js`: `xbox` in `TABS`, `xbox: "Xbox"` in `NAMES`.
## Config
```toml
[xbox]
# The Azure app's client id (a public client for personal Microsoft
# accounts). Empty: the Xbox tab says it is not configured.
client_id = ""
```
`[modules] xbox = true`.
## Skipped
Captures (screenshots and clips), sending messages, friend management, the
store, a Dashboard chip (the auto-switch replaces it), a CLI login.
## Tests
`tests/test_xbox.py` with a fake HTTP function: the token chain and its
refresh and failure, device code polling, presence parsing, game vs app,
session edges, the status file, action validation. `node --check
static/modules/xbox.js`.
|