Gamerig Library: gamerig's game library as a Chandra desktop module
CI / test (push) Successful in 2m25s
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:
57 files changed
+3551
-29
No files matched your search
@@ -296,6 +296,9 @@ impl chandra::host::plasmoids::Host for State {
|
||||
Req::DefaultApp(code) => R::DefaultApp(code),
|
||||
Req::SetDesktop(i) => R::SetDesktop(i),
|
||||
Req::FaceUnlock(code) => R::FaceUnlock(code),
|
||||
Req::GameLibrary(action, game, mode) => {
|
||||
R::GameLibrary(chandra::host::plasmoids::GameRequest { action, game, mode })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+129
-2
@@ -76,6 +76,8 @@ pub enum Req {
|
||||
/// A face-unlock request: a face index removes it; -1 refresh, -2 enroll, -3 / -4 stop /
|
||||
/// start using it.
|
||||
FaceUnlock(i32),
|
||||
/// A game-library action (0 launch, 1 stop, 2 focus, 3 refresh), the game and the mode.
|
||||
GameLibrary(i32, String, String),
|
||||
}
|
||||
|
||||
pub const T_APPS: usize = 0;
|
||||
@@ -103,11 +105,18 @@ pub const T_DESKTOPS: usize = 20;
|
||||
pub const T_FACE_STATUS: usize = 24;
|
||||
/// Enrolled faces (ss): label added.
|
||||
pub const T_FACES: usize = 25;
|
||||
/// Game library status, one row (ssssssii): error gpu resolution display audio hostname connected
|
||||
/// audio-ok.
|
||||
pub const T_GL_STATUS: usize = 26;
|
||||
/// Games (ssssssiii): id name category description icon install-hint featured installed running.
|
||||
pub const T_GL_GAMES: usize = 27;
|
||||
/// Extra launch modes (sss): game id label.
|
||||
pub const T_GL_MODES: usize = 28;
|
||||
|
||||
/// Host data every module reads from, shared by all loaded modules.
|
||||
#[derive(Default)]
|
||||
pub struct Shared {
|
||||
pub tables: [Vec<u8>; 26],
|
||||
pub tables: [Vec<u8>; 29],
|
||||
pub layout_mode: i32,
|
||||
pub wallpaper: i32,
|
||||
/// What fills the desktop (an index into the desktops table).
|
||||
@@ -418,6 +427,70 @@ impl d::face_unlock::Host for PState {
|
||||
}
|
||||
}
|
||||
|
||||
impl d::game_library::Host for PState {
|
||||
fn status(&mut self) -> d::game_library::RigStatus {
|
||||
let rows = self.rows(T_GL_STATUS, "ssssssii");
|
||||
match rows.first() {
|
||||
Some(r) if r.len() == 8 => d::game_library::RigStatus {
|
||||
error: s(&r[0]),
|
||||
gpu: s(&r[1]),
|
||||
resolution: s(&r[2]),
|
||||
display: s(&r[3]),
|
||||
audio: s(&r[4]),
|
||||
hostname: s(&r[5]),
|
||||
connected: i(&r[6]) != 0,
|
||||
audio_ok: i(&r[7]) != 0,
|
||||
},
|
||||
_ => d::game_library::RigStatus {
|
||||
error: String::new(),
|
||||
gpu: String::new(),
|
||||
resolution: String::new(),
|
||||
display: String::new(),
|
||||
audio: String::new(),
|
||||
hostname: String::new(),
|
||||
connected: false,
|
||||
audio_ok: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
fn games(&mut self) -> Vec<d::game_library::Game> {
|
||||
self.rows(T_GL_GAMES, "ssssssiii")
|
||||
.iter()
|
||||
.filter(|r| r.len() == 9)
|
||||
.map(|r| d::game_library::Game {
|
||||
id: s(&r[0]),
|
||||
name: s(&r[1]),
|
||||
category: s(&r[2]),
|
||||
description: s(&r[3]),
|
||||
icon: s(&r[4]),
|
||||
install_hint: s(&r[5]),
|
||||
featured: i(&r[6]) != 0,
|
||||
installed: i(&r[7]) != 0,
|
||||
running: i(&r[8]) != 0,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
fn launch_modes(&mut self) -> Vec<d::game_library::LaunchMode> {
|
||||
self.rows(T_GL_MODES, "sss")
|
||||
.iter()
|
||||
.filter(|r| r.len() == 3)
|
||||
.map(|r| d::game_library::LaunchMode { game: s(&r[0]), id: s(&r[1]), label: s(&r[2]) })
|
||||
.collect()
|
||||
}
|
||||
fn launch(&mut self, game: String, mode: String) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::GameLibrary(0, game, mode));
|
||||
}
|
||||
fn stop(&mut self, game: String) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::GameLibrary(1, game, String::new()));
|
||||
}
|
||||
fn focus(&mut self, game: String) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::GameLibrary(2, game, String::new()));
|
||||
}
|
||||
fn refresh(&mut self) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::GameLibrary(3, String::new(), String::new()));
|
||||
}
|
||||
}
|
||||
|
||||
impl d::power::Host for PState {
|
||||
fn screen_off_minutes(&mut self) -> u32 {
|
||||
self.shared.borrow().screen_off_min
|
||||
@@ -1210,4 +1283,58 @@ mod tests {
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::Network(2, _, _))));
|
||||
rt.unload(h);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gamerig_library_shows_the_daemons_games_and_launches_big_picture() {
|
||||
let mut rt = runtime();
|
||||
let l = rt.load(&module("gamerig-library")).expect("gamerig-library loads");
|
||||
assert!(l.imports.contains(&"game-library".to_string()));
|
||||
let h = l.handle;
|
||||
{
|
||||
let mut sh = rt.shared.borrow_mut();
|
||||
sh.tables[T_GL_STATUS] = rows_table(&[vec![
|
||||
F::S(""),
|
||||
F::S("NVIDIA GeForce GTX 1650"),
|
||||
F::S("1280x720"),
|
||||
F::S(":0"),
|
||||
F::S("PulseAudio"),
|
||||
F::S("rig"),
|
||||
F::I(1),
|
||||
F::I(1),
|
||||
]]);
|
||||
sh.tables[T_GL_GAMES] = rows_table(&[vec![
|
||||
F::S("steam"),
|
||||
F::S("Steam"),
|
||||
F::S("games"),
|
||||
F::S("Your Steam library."),
|
||||
F::S("Play"),
|
||||
F::S(""),
|
||||
F::I(1),
|
||||
F::I(1),
|
||||
F::I(0),
|
||||
]]);
|
||||
sh.tables[T_GL_MODES] = rows_table(&[vec![F::S("steam"), F::S("bigpicture"), F::S("Big Picture")]]);
|
||||
}
|
||||
let ops = rt.render(h, Size { w: 1280, h: 720 });
|
||||
let t = texts(&ops);
|
||||
for n in ["Gamerig", "Steam", "Big Picture", "Rig Status", "PulseAudio"] {
|
||||
assert!(t.contains(&n.to_string()), "{n} shown");
|
||||
}
|
||||
// Click Big Picture: a launch request with its mode.
|
||||
let at = ops
|
||||
.iter()
|
||||
.find_map(|o| match o {
|
||||
d::types::DrawOp::Text(t) if t.text == "Big Picture" => Some(t.origin),
|
||||
_ => None,
|
||||
})
|
||||
.expect("Big Picture button");
|
||||
let p = Point { x: at.x + 4, y: at.y };
|
||||
rt.on_event(h, false, InputEvent::PointerDown(p));
|
||||
rt.on_event(h, false, InputEvent::PointerUp(p));
|
||||
match rt.shared.borrow_mut().requests.pop_front() {
|
||||
Some(Req::GameLibrary(0, game, mode)) => assert_eq!((game.as_str(), mode.as_str()), ("steam", "bigpicture")),
|
||||
other => panic!("expected a launch, got {:?}", other.is_some()),
|
||||
}
|
||||
rt.unload(h);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user