Gamerig Library: gamerig's game library as a Chandra desktop module
CI / test (push) Successful in 2m25s

- New desktop module gamerig-library (components/gamerig-library, logic in lib/gamelib): the
  layout of gamerig's web library (desktop/ui) in draw ops. Top bar with the Gamerig mark, app
  count and search; sidebar with categories and counts, running apps (switch to, stop) and rig
  status (GPU, display, audio); card grid with featured games two columns wide, icon tiles,
  category and status badges, description, install hint, Launch / Big Picture / Switch to / Stop.
  Typing filters, arrows + Enter launch, the wheel scrolls. Colours: follow desktop, dark, light.
- New game-library capability: tables 26-28 (status, games, launch modes), request 45, in the
  wasmer/wasmtime stub, the MoonBit wasmhost and the Rust host-wasm.
- compositor/shell/gamelib.mbt polls GET $GAMERIG_DESKTOP_API/api/state (default
  http://127.0.0.1:8091) every 2 s with curl on a socket and POSTs launch/stop/focus; a file://
  base reads a state file (tests).
- --desktop NAME picks what fills the desktop at start. scripts/gamerig-kiosk.sh now runs a
  hybrid kiosk with the library as the desktop (CHANDRA_KIOSK_MODE=strict for the old one).
- Tests: lib/gamelib, compositor/host/gamelib_test.mbt, a host-wasm test; docs/gamerig-library.md
  with a screenshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgvjzw8hHirxRsXSsE
This commit is contained in:
Claude committed 2026-11-26 02:57:07 +00:00
1 parent fa932f9ac0
commit f556df2f4b
57 files changed
+3551 -29

No files matched your search

+171
View File
@@ -0,0 +1,171 @@
///| A /api/state answer like gamerig's server.py gives.
let sample : String =
#|{"system": {"gpu": "NVIDIA GeForce GTX 1650", "resolution": "1920x1080", "display": ":0",
#| "audio": "PulseAudio (Selkies)", "audio_ok": true, "hostname": "rig"},
#| "apps": [
#| {"id": "steam", "name": "Steam", "category": "games", "featured": true, "icon": "Play",
#| "description": "Your Steam library, store and friends.", "installed": true, "running": false,
#| "modes": [{"id": "default", "label": "Launch"}, {"id": "bigpicture", "label": "Big Picture"}]},
#| {"id": "lutris", "name": "Lutris", "category": "launchers", "icon": "Folder",
#| "description": "Open gaming platform.", "installed": false, "install_hint": "apt-get install lutris"},
#| {"id": "terminal", "name": "Terminal", "category": "tools", "icon": "Terminal",
#| "description": "Interactive shell inside the rig.", "installed": true, "running": true, "pid": 42},
#| {"name": "no id"}
#| ]}
///|
fn sample_state() -> @gamelib.State {
match @gamelib.parse_state(sample) {
Ok(s) => s
Err(e) => abort(e)
}
}
///|
fn tokens() -> @theme.Tokens {
let c = @ui.color(230, 230, 230, 255)
{
name: "dark",
palette: {
desktop_top: c,
desktop_bottom: c,
surface: c,
surface_hover: c,
surface_popup: c,
foreground: c,
foreground_muted: c,
accent: c,
accent_foreground: c,
border: c,
},
font_size: 14,
radius: 8,
spacing: 8,
panel_height: 40,
}
}
///|
fn texts(ops : Array[@types.DrawOp]) -> Array[String] {
let out : Array[String] = []
for op in ops {
if op is Text(t) {
out.push(t.text)
}
}
out
}
///|
test "parse_state reads the rig, the games and their extra modes" {
let s = sample_state()
assert_eq(s.rig.gpu, "NVIDIA GeForce GTX 1650")
assert_true(s.rig.connected)
assert_true(s.rig.audio_ok)
assert_eq(s.games.map(g => g.id), ["steam", "lutris", "terminal"])
assert_eq(s.modes, [{ game: "steam", id: "bigpicture", label: "Big Picture" }])
assert_eq(s.games[1].install_hint, "apt-get install lutris")
assert_eq(s.games[2].status(), Running)
assert_true(@gamelib.parse_state("nope") is Err(_))
assert_eq(@gamelib.error_message("{\"error\": \"unknown app\"}"), "unknown app")
}
///|
test "filtering: categories, running, search words, featured first" {
let g = sample_state().games
assert_eq(@gamelib.count_in(g, All), 3)
assert_eq(@gamelib.count_in(g, Games), 1)
assert_eq(@gamelib.count_in(g, Running), 1)
assert_eq(@gamelib.filter_games(g, All, "shell rig").map(x => x.id), ["terminal"])
assert_eq(@gamelib.filter_games(g, All, "").map(x => x.id), ["steam", "lutris", "terminal"])
assert_eq(@gamelib.filter_games(g, Tools, "steam").length(), 0)
}
///|
test "wrap and ellipsize keep to the width" {
let lines = @gamelib.wrap("one two three four five six seven", 60, 10, 2)
assert_eq(lines.length(), 2)
for l in lines {
assert_true(@gamelib.approx_width(l, 10) <= 60)
}
assert_true(lines[1].has_suffix("…"))
assert_eq(@gamelib.ellipsize("short", 100, 10), "short")
}
///|
test "grid: featured cards span two columns, rows wrap" {
let g = sample_state().games
let (cells, total, cols) = @gamelib.grid_layout(g, 900)
assert_eq(cols, 3)
// steam (featured) two columns, lutris next to it, terminal on the next row.
assert_eq(cells[0].3 > cells[1].3, true)
assert_eq(cells[1].2, 0)
assert_true(cells[2].2 > 0)
assert_true(total >= cells[2].2 + cells[2].4)
// One column: nothing spans.
let (one, _, c1) = @gamelib.grid_layout(g, 300)
assert_eq(c1, 1)
assert_eq(one[0].3, one[1].3)
}
///|
test "render shows the sidebar, the cards and the rig; clicks launch, stop and filter" {
let lib = @gamelib.Library::new()
let s = sample_state()
let size : @types.Size = { w: 1600, h: 1000 }
let ops = lib.render(s.games, s.modes, s.rig, size, tokens())
let t = texts(ops)
for want in ["Gamerig", "Library", "Games", "Running Apps", "Rig Status", "Steam", "Big Picture", "Switch to", "Stop", "Not installed", "All apps"] {
assert_true(t.contains(want), msg="missing " + want)
}
assert_true(t.iter().any(x => x.has_prefix("NVIDIA GeForce")))
let click = (h : @gamelib.Hit) => {
for reg in lib.regions {
if reg.1 == h {
let p : @types.Point = { x: reg.0.x + 2, y: reg.0.y + 2 }
ignore(lib.handle(PointerDown(p)))
return lib.handle(PointerUp(p)).1
}
}
abort("no region")
}
assert_eq(click(Button("steam", "bigpicture")), Launch("steam", "bigpicture"))
assert_eq(click(Button("steam", "default")), Launch("steam", "default"))
assert_eq(click(StopButton("terminal")), Stop("terminal"))
assert_eq(click(RunningRow("terminal")), Focus("terminal"))
assert_eq(click(RefreshButton), Refresh)
assert_eq(click(Cat(Tools)), NoAction)
assert_eq(lib.category, Tools)
let t = texts(lib.render(s.games, s.modes, s.rig, size, tokens()))
assert_false(t.contains("Steam"))
assert_true(t.contains("Terminal"))
}
///|
test "typing filters, Enter launches the selection, Escape clears" {
let lib = @gamelib.Library::new()
let s = sample_state()
let size : @types.Size = { w: 1280, h: 720 }
ignore(lib.render(s.games, s.modes, s.rig, size, tokens()))
for k in ["l", "u", "t"] {
ignore(lib.handle(KeyDown(k)))
}
assert_eq(lib.query, "lut")
ignore(lib.render(s.games, s.modes, s.rig, size, tokens()))
ignore(lib.handle(KeyDown("Right")))
assert_eq(lib.selected, "lutris")
assert_eq(lib.handle(KeyDown("Enter")).1, Launch("lutris", "default"))
ignore(lib.handle(KeyDown("Backspace")))
assert_eq(lib.query, "lu")
ignore(lib.handle(KeyDown("Escape")))
assert_eq(lib.query, "")
}
///|
test "disconnected: says it is waiting, and the error" {
let lib = @gamelib.Library::new()
let rig = { ..@gamelib.Rig::unknown(), error: "Library daemon not reachable" }
let t = texts(lib.render([], [], rig, { w: 1280, h: 720 }, tokens()))
assert_true(t.contains("Waiting for the library daemon…"))
assert_true(t.contains("Library daemon not reachable"))
}