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:
@@ -100,6 +100,15 @@ pub struct FeatureSettings {
|
||||
pub browser_share: bool,
|
||||
}
|
||||
|
||||
/// Game detection (admin.spec.md, "Game detection"): on by default; the person's own games and
|
||||
/// programs that are never games, as program file names (".exe" may be left out).
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct GameSettings {
|
||||
pub detect: bool,
|
||||
pub games: Vec<String>,
|
||||
pub not_games: Vec<String>,
|
||||
}
|
||||
|
||||
/// Background collection (admin.spec.md, "Background collection"); no targets by default.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct CollectSettings {
|
||||
@@ -146,6 +155,7 @@ pub struct Settings {
|
||||
pub features: FeatureSettings,
|
||||
pub mcp_servers: Vec<McpServerSettings>,
|
||||
pub collect: CollectSettings,
|
||||
pub game: GameSettings,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -192,6 +202,7 @@ impl Default for Settings {
|
||||
features: FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false },
|
||||
mcp_servers: vec![],
|
||||
collect: CollectSettings { keep_days: 30, targets: vec![] },
|
||||
game: GameSettings { detect: true, games: vec![], not_games: vec![] },
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -516,6 +527,7 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
|
||||
},
|
||||
mcp_servers: parse_mcp_servers(raw)?,
|
||||
collect: parse_collect(raw, &d.collect)?,
|
||||
game: parse_game(raw, &d.game)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -541,6 +553,20 @@ fn get_uint(m: Option<&Map<String, Value>>, key: &str, path: &str, default: u32,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_game(raw: &Map<String, Value>, d: &GameSettings) -> Result<GameSettings, SettingsError> {
|
||||
let g = section(raw, "game")?;
|
||||
let list = |key: &str, default: &[String]| -> Result<Vec<String>, SettingsError> {
|
||||
let v: Vec<String> = get_str_list(g, key, "game", default)?.into_iter().map(|e| e.trim().to_owned())
|
||||
.filter(|e| !e.is_empty()).collect();
|
||||
if v.len() > 100 || v.iter().any(|e| e.chars().count() > 100 || e.contains(['\\', '/'])) {
|
||||
return err(format!("game.{key} must be at most 100 program names (no folders)"));
|
||||
}
|
||||
Ok(v)
|
||||
};
|
||||
Ok(GameSettings { detect: get_bool(g, "detect", "game", d.detect)?, games: list("games", &d.games)?,
|
||||
not_games: list("notGames", &d.not_games)? })
|
||||
}
|
||||
|
||||
fn parse_collect(raw: &Map<String, Value>, d: &CollectSettings) -> Result<CollectSettings, SettingsError> {
|
||||
let c = section(raw, "collect")?;
|
||||
let keep_days = get_uint(c, "keepDays", "collect", d.keep_days, 1, 365)?;
|
||||
@@ -808,6 +834,16 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn game_detection_settings_are_read_and_checked() {
|
||||
assert_eq!(parse_settings(&json!({})).unwrap().game, GameSettings { detect: true, games: vec![], not_games: vec![] });
|
||||
let s = parse_settings(&json!({"game": {"detect": false, "games": [" MyGame.exe ", ""], "notGames": ["obs64"]}})).unwrap();
|
||||
assert_eq!(s.game, GameSettings { detect: false, games: vec!["MyGame.exe".into()], not_games: vec!["obs64".into()] });
|
||||
for bad in [json!({"game": {"games": ["C:\\x\\a.exe"]}}), json!({"game": {"notGames": "a"}}), json!({"game": {"detect": 1}})] {
|
||||
assert!(parse_settings(&bad).unwrap_err().0.contains("game."), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn features_and_mcp_servers_are_read_and_checked() {
|
||||
let s = parse_settings(&json!({}));
|
||||
|
||||
Reference in New Issue
Block a user