feat(app): game detection for the performance stages
- while the services run the app looks at the foreground window every 2 s (Windows): the person's notGames and games lists first, never a browser, video player, the desktop, Discord, a launcher's own window or this app; a program under a Steam, Epic, Riot or Battle.net game folder, exclusive full screen, or a window covering a monitor without title bar or border whose process uses at least 10% of the GPU's 3D engine (the M0 rule) is a game - game mode stays until that game's process ends, also behind other windows; the dashboard shows "게임 모드: 켜짐 (name, reason)" and the game log tab its changes - a 게임 모드 settings screen (detection on/off, the two lists) - checked on the win-ci VM: a program in a Steam game folder turned it on after 1.4 s and off 2.0 s after it ended Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
42
app/tests/game_watch.rs
Normal file
42
app/tests/game_watch.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
//! Game detection on Windows (admin.spec.md, "Game detection"): a program started from a launcher's
|
||||
//! game folder turns game mode on with the folder's name, and off once it ends. Runs only with
|
||||
//! `JARVIS_TEST_GAME_EXE=<a windowed program under ...\steamapps\common\<Game>\>`; elsewhere it skips.
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use jarvis_app::game::GameWatch;
|
||||
use jarvis_app::settings::GameSettings;
|
||||
|
||||
fn wait_for(w: &GameWatch, want: impl Fn(&serde_json::Value) -> bool, secs: u64) -> serde_json::Value {
|
||||
let until = Instant::now() + Duration::from_secs(secs);
|
||||
loop {
|
||||
let v = w.view();
|
||||
if want(&v) || Instant::now() > until {
|
||||
return v;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(200));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_launcher_game_turns_game_mode_on_until_it_ends() {
|
||||
let Ok(exe) = std::env::var("JARVIS_TEST_GAME_EXE") else {
|
||||
eprintln!("skipped: set JARVIS_TEST_GAME_EXE");
|
||||
return;
|
||||
};
|
||||
let w = GameWatch::start(GameSettings { detect: true, games: vec![], not_games: vec![] });
|
||||
assert_eq!(w.view(), serde_json::Value::Null, "no game before it starts");
|
||||
let mut game = std::process::Command::new(&exe).spawn().expect("the game starts");
|
||||
let t0 = Instant::now();
|
||||
let on = wait_for(&w, |v| !v.is_null(), 15);
|
||||
eprintln!("on after {:?}: {on}", t0.elapsed());
|
||||
let folder = std::path::Path::new(&exe).parent().unwrap().file_name().unwrap().to_string_lossy().into_owned();
|
||||
assert_eq!(on, serde_json::json!({"name": folder, "reason": {"kind": "launcher", "launcher": "Steam"}}));
|
||||
game.kill().unwrap();
|
||||
let _ = game.wait();
|
||||
let t1 = Instant::now();
|
||||
let off = wait_for(&w, |v| v.is_null(), 10);
|
||||
eprintln!("off after {:?}: {off}", t1.elapsed());
|
||||
assert_eq!(off, serde_json::Value::Null, "game mode ends with the game");
|
||||
w.stop();
|
||||
}
|
||||
Reference in New Issue
Block a user