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
113 lines
4.7 KiB
MoonBit
113 lines
4.7 KiB
MoonBit
///| The Gamerig Library desktop module and the `game-library` capability (compositor/shell/
|
|
/// gamelib.mbt), against a state file standing in for gamerig's library daemon. Needs the module
|
|
/// built: scripts/build-modules.sh.
|
|
|
|
///|
|
|
let gamelib_state_idle : String =
|
|
#|{"system": {"gpu": "NVIDIA GeForce GTX 1650", "resolution": "1280x720", "display": ":0",
|
|
#| "audio": "PulseAudio", "audio_ok": true, "hostname": "rig"},
|
|
#| "apps": [
|
|
#| {"id": "steam", "name": "Steam", "category": "games", "featured": true, "icon": "Play",
|
|
#| "description": "Your Steam library.", "installed": true, "running": false,
|
|
#| "modes": [{"id": "default", "label": "Launch"}, {"id": "bigpicture", "label": "Big Picture"}]},
|
|
#| {"id": "terminal", "name": "Terminal", "category": "tools", "icon": "Terminal",
|
|
#| "description": "Interactive shell inside the rig.", "installed": true}
|
|
#| ]}
|
|
|
|
///|
|
|
fn gamelib_file(tag : String, body : String) -> String {
|
|
let path = "/tmp/chandra-gamelib-" + tag + "-" + @sys.getpid().to_string() + ".json"
|
|
ignore(@sys.write_file_bytes(path, @sys.str_to_utf8_bytes(body)))
|
|
path
|
|
}
|
|
|
|
///| The desktop module's texts and where each is drawn.
|
|
fn gamelib_texts(comp : @host.ChandraCompositor) -> Array[(String, Int, Int)] {
|
|
let out : Array[(String, Int, Int)] = []
|
|
for op in comp.shell.slot_ops("desktop") {
|
|
if op is Text(t) {
|
|
out.push((t.text, t.origin.x, t.origin.y))
|
|
}
|
|
}
|
|
out
|
|
}
|
|
|
|
///|
|
|
fn gamelib_has(comp : @host.ChandraCompositor, s : String) -> Bool {
|
|
gamelib_texts(comp).iter().any(t => t.0 == s)
|
|
}
|
|
|
|
///| Click the first text `label` the module drew.
|
|
fn gamelib_click(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit {
|
|
for tx in gamelib_texts(comp) {
|
|
if tx.0 == label {
|
|
comp.handle_input(@nested.InputEvent::PointerMove((tx.1 + 4).to_double(), tx.2.to_double()), t)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), t + 1U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), t + 2U)
|
|
ignore(comp.compose_frame())
|
|
return
|
|
}
|
|
}
|
|
abort("no " + label)
|
|
}
|
|
|
|
///|
|
|
test "the Gamerig Library shows the daemon's games and rig, and sends launch / stop / focus" {
|
|
let comp = desk_comp("gamelib")
|
|
let path = gamelib_file("a", gamelib_state_idle)
|
|
comp.shell.set_gamelib_base("file://" + path)
|
|
assert_true(comp.shell.desktop_modules().contains(("gamerig-library", "Gamerig Library")))
|
|
assert_true(comp.shell.set_desktop("gamerig-library"))
|
|
ignore(comp.compose_frame())
|
|
ignore(comp.compose_frame())
|
|
for want in ["Gamerig", "Steam", "Terminal", "Big Picture", "Rig Status", "Games", "Running Apps"] {
|
|
assert_true(gamelib_has(comp, want), msg="missing " + want)
|
|
}
|
|
// Launch Big Picture, then plain Launch on the first card (Steam, featured).
|
|
gamelib_click(comp, "Big Picture", 100U)
|
|
gamelib_click(comp, "Launch", 110U)
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.gamelib.sent, ["launch steam bigpicture", "launch steam default"])
|
|
// The daemon says it runs now: the card offers Switch to and Stop, the sidebar lists it.
|
|
ignore(@sys.write_file_bytes(path, @sys.str_to_utf8_bytes(gamelib_state_idle.replace(old="\"running\": false", new="\"running\": true"))))
|
|
comp.shell.gamelib.next_poll = 0UL
|
|
ignore(comp.compose_frame())
|
|
ignore(comp.compose_frame())
|
|
assert_true(gamelib_has(comp, "Switch to"))
|
|
gamelib_click(comp, "Stop", 120U)
|
|
gamelib_click(comp, "Switch to", 130U)
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.gamelib.sent[2:].to_owned(), ["stop steam default", "focus steam default"])
|
|
// The daemon goes away: the library says so.
|
|
@sys.unlink(path)
|
|
comp.shell.gamelib.next_poll = 0UL
|
|
ignore(comp.compose_frame())
|
|
ignore(comp.compose_frame())
|
|
assert_true(gamelib_texts(comp).iter().any(t => t.0.has_prefix("Library daemon not reachable")))
|
|
}
|
|
|
|
///|
|
|
test "typing on the focused library filters its cards" {
|
|
let comp = desk_comp("gamelib-type")
|
|
let path = gamelib_file("b", gamelib_state_idle)
|
|
comp.shell.set_gamelib_base("file://" + path)
|
|
assert_true(comp.shell.set_desktop("gamerig-library"))
|
|
ignore(comp.compose_frame())
|
|
ignore(comp.compose_frame())
|
|
// A click on the empty grid gives the desktop the keyboard.
|
|
comp.handle_input(@nested.InputEvent::PointerMove(900.0, 600.0), 10U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 11U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 12U)
|
|
ignore(comp.compose_frame())
|
|
for k in [20U, 18U, 19U, 50U] { // t e r m (evdev codes)
|
|
comp.handle_input(@nested.InputEvent::Key(k, true), 20U)
|
|
comp.handle_input(@nested.InputEvent::Key(k, false), 21U)
|
|
}
|
|
ignore(comp.compose_frame())
|
|
assert_true(gamelib_has(comp, "term"))
|
|
assert_true(gamelib_has(comp, "Terminal"))
|
|
assert_false(gamelib_has(comp, "Steam"))
|
|
@sys.unlink(path)
|
|
}
|
|
|