feat(game): pure detection seams — matcher, debouncer, VDF parser, config
Step 1 of the game-detection feature (game-presence-plan.md): all the pure, I/O-free logic, tested first. - src/game/mod.rs: DetectedGame + stable namespaced ids (steam:730 / exe:hl2_linux, never the mutable name); ManualOverride; the priority resolve() matcher (override -> Steam -> mapped process -> none); the Debouncer (2-on/3-off, immediate bypass for manual override) that stops a flapping detector re-announcing the ~48KB-avatar PeerState; match_processes() over explicit user mappings with a launcher denylist (never guesses a game from an arbitrary process). - src/game/vdf.rs: a real recursive-descent KeyValues/VDF parser (not a name-regex) for appmanifest/.acf, libraryfolders.vdf, registry.vdf — depth-capped, escape-aware, never panics on malformed/truncated input. - src/sanitize.rs: sanitize_game_label (64-char/256-byte cap, wider than the 48-char name cap) sharing the bidi/zero-width cleaning. - src/config.rs: additive game_presence_enabled (opt-in, default OFF), game_backgrounds + game_process_map (BTreeMap, deterministic); background_path generalized to hashed per-game files; explicit legacy-config migration test (load() wipes on any deserialize error). - src/background.rs: game_background_filename (FNV-1a hashed, fs-safe). No wire/protocol change yet; no OS reads yet. 386 lib tests (+28). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,22 @@ pub fn process_background(raw: &[u8]) -> Result<Vec<u8>, String> {
|
||||
Ok(png.into_inner())
|
||||
}
|
||||
|
||||
/// A filesystem-safe, app-owned filename for the processed PNG of a per-game
|
||||
/// background (W18), derived from the game's stable id by hashing rather than
|
||||
/// embedding the raw id: keeps the name short and safe (ids contain `:` and
|
||||
/// arbitrary executable basenames) and avoids leaking the id into the filesystem.
|
||||
/// Deterministic and dependency-free (FNV-1a 64-bit), so the same game id always
|
||||
/// maps to the same file.
|
||||
pub fn game_background_filename(game_id: &str) -> String {
|
||||
// FNV-1a, 64-bit.
|
||||
let mut hash: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
for b in game_id.as_bytes() {
|
||||
hash ^= *b as u64;
|
||||
hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
|
||||
}
|
||||
format!("game-bg-{hash:016x}.png")
|
||||
}
|
||||
|
||||
/// The legibility scrim drawn between the background image and the UI: the active
|
||||
/// theme's base colour at `dim` alpha (clamped to `0.0..=1.0`). A higher `dim`
|
||||
/// recedes the image so body text and panel chrome stay readable, and it re-tints
|
||||
@@ -90,6 +106,17 @@ mod tests {
|
||||
assert!(process_background(b"definitely not an image").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn game_background_filename_is_stable_safe_and_distinct() {
|
||||
let a = game_background_filename("steam:730");
|
||||
// Stable for the same id.
|
||||
assert_eq!(a, game_background_filename("steam:730"));
|
||||
// Distinct ids → distinct files (no `:` or path chars leak through).
|
||||
assert_ne!(a, game_background_filename("exe:hl2_linux"));
|
||||
assert!(a.starts_with("game-bg-") && a.ends_with(".png"));
|
||||
assert!(!a.contains(':') && !a.contains('/') && !a.contains('\\'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scrim_color_sets_alpha_and_keeps_rgb() {
|
||||
let base = Color::from_rgb(0.1, 0.2, 0.3);
|
||||
|
||||
Reference in New Issue
Block a user