Repository navigation
feat(games): rescan button and launcher-agnostic install detection #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a04a739
0c0ad89
736d22b
ed3b22b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,20 +69,24 @@ impl GameWatcher { | |
| .await; | ||
| loop { | ||
| let started = Instant::now(); | ||
| let (updated, changes) = cx | ||
| let (updated, scanned) = cx | ||
| .background_executor() | ||
| .spawn(async move { | ||
| let changes = tracker.poll(); | ||
| (tracker, changes) | ||
| let scanned = tracker.poll(); | ||
| (tracker, scanned) | ||
| }) | ||
| .await; | ||
| tracker = updated; | ||
| if changes.is_empty() { | ||
| // Reconcile against the view's *current* state, not a private | ||
| // delta baseline: a manual rescan may have changed installed | ||
| // flags since this tracker last looked. Unchanged values are | ||
| // no-ops in `apply_game_updates`, so this only corrects drift. | ||
| if scanned.is_empty() { | ||
| if view.upgrade().is_none() { | ||
| break; | ||
| } | ||
| } else if view | ||
| .update(cx, |view, cx| view.apply_game_updates(&changes, cx)) | ||
| .update(cx, |view, cx| view.apply_game_updates(&scanned, cx)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject periodic results superseded by a manual rescan. A periodic scan can record The previous private baseline suppressed that unchanged Coordinate scan generations or serialize installation scans. Reject superseded results while retaining full-state reconciliation for current results.
|
||
| .is_err() | ||
| { | ||
| break; | ||
|
|
@@ -130,6 +134,30 @@ pub(crate) fn apply_updates(catalog: &mut [Game], updates: &[GameUpdate]) -> boo | |
| changed | ||
| } | ||
|
|
||
| /// One-off install scan for the Games page's Rescan button. Blocking (reads | ||
| /// launcher manifests and the registry), so callers must run it off the UI | ||
| /// thread. The returned updates carry only `installed`, leaving the running | ||
| /// state to the two-second process tracker. | ||
| pub(crate) fn scan_installed(catalog: &[Game]) -> Vec<GameUpdate> { | ||
| let mut scanned = catalog.to_vec(); | ||
| games::mark_installed(&mut scanned); | ||
| install_updates(catalog, &scanned) | ||
|
macroscopeapp[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| fn install_updates(previous: &[Game], scanned: &[Game]) -> Vec<GameUpdate> { | ||
| previous | ||
| .iter() | ||
| .zip(scanned) | ||
| .filter_map(|(before, after)| { | ||
| (before.installed != after.installed).then(|| GameUpdate { | ||
| id: before.id.clone(), | ||
| installed: Some(after.installed), | ||
| running: None, | ||
| }) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| struct RunningTracker { | ||
| system: System, | ||
| matches: ProcessMatches, | ||
|
|
@@ -284,33 +312,30 @@ fn executable_basename(name: &str) -> &str { | |
|
|
||
| struct InstallationTracker { | ||
| catalog: Vec<Game>, | ||
| installed: Vec<bool>, | ||
| } | ||
|
|
||
| impl InstallationTracker { | ||
| fn new(catalog: Vec<Game>) -> Self { | ||
| let installed = catalog.iter().map(|game| game.installed).collect(); | ||
| Self { catalog, installed } | ||
| Self { catalog } | ||
| } | ||
|
|
||
| fn poll(&mut self) -> Vec<GameUpdate> { | ||
| games::mark_installed(&mut self.catalog); | ||
| self.updates() | ||
| self.state_updates() | ||
| } | ||
|
|
||
| fn updates(&mut self) -> Vec<GameUpdate> { | ||
| let mut changes = Vec::new(); | ||
| for (game, previous) in self.catalog.iter().zip(&mut self.installed) { | ||
| if game.installed != *previous { | ||
| changes.push(GameUpdate { | ||
| id: game.id.clone(), | ||
| installed: Some(game.installed), | ||
| running: None, | ||
| }); | ||
| *previous = game.installed; | ||
| } | ||
| } | ||
| changes | ||
| /// Every game's current installed state, not just transitions. The view | ||
| /// applies this against its own flags, so a manual rescan cannot leave a | ||
| /// stale value that this tracker's private baseline would never correct. | ||
| fn state_updates(&self) -> Vec<GameUpdate> { | ||
| self.catalog | ||
| .iter() | ||
| .map(|game| GameUpdate { | ||
| id: game.id.clone(), | ||
| installed: Some(game.installed), | ||
| running: None, | ||
| }) | ||
| .collect() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -455,19 +480,41 @@ mod tests { | |
| } | ||
|
|
||
| #[test] | ||
| fn installation_lifecycle_does_not_reset_concurrent_running_state() { | ||
| fn periodic_install_state_reconciles_manual_changes_and_preserves_running() { | ||
| let mut tracker = InstallationTracker::new(vec![game("cs2", "cs2.exe")]); | ||
| let mut catalog = vec![game("cs2", "cs2.exe")]; | ||
| catalog[0].running = true; | ||
| assert!(tracker.updates().is_empty()); | ||
| tracker.catalog[0].installed = true; | ||
| assert!(apply_updates(&mut catalog, &tracker.updates())); | ||
| assert!(catalog[0].installed && catalog[0].running); | ||
| assert!(tracker.updates().is_empty()); | ||
| // Unchanged values are reported too, but applying them is a no-op. | ||
| assert_eq!(tracker.state_updates().len(), 1); | ||
| assert!(!apply_updates(&mut catalog, &tracker.state_updates())); | ||
|
|
||
| // A manual rescan marks it installed; it is then uninstalled before | ||
| // the periodic scan runs. The next poll must still clear the UI flag. | ||
| catalog[0].installed = true; | ||
| tracker.catalog[0].installed = false; | ||
| assert!(apply_updates(&mut catalog, &tracker.updates())); | ||
| assert!(apply_updates(&mut catalog, &tracker.state_updates())); | ||
| assert!(!catalog[0].installed && catalog[0].running); | ||
| assert!(tracker.updates().is_empty()); | ||
| assert!(!apply_updates(&mut catalog, &tracker.state_updates())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn manual_install_scan_reports_only_installed_changes() { | ||
| let mut before = vec![game("cs2", "cs2.exe"), game("valorant", "VALORANT.exe")]; | ||
| before[0].running = true; | ||
| let mut after = before.clone(); | ||
| after[0].installed = true; | ||
| let updates = install_updates(&before, &after); | ||
| assert_eq!( | ||
| updates, | ||
| vec![GameUpdate { | ||
| id: "cs2".into(), | ||
| installed: Some(true), | ||
| running: None, | ||
| }] | ||
| ); | ||
| assert!(apply_updates(&mut before, &updates)); | ||
| assert!(before[0].installed && before[0].running, "running state survives"); | ||
| assert!(!apply_updates(&mut before, &updates), "no duplicate change"); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep manual updates consistent with the periodic tracker.
The periodic tracker compares scans with its private
installedvector, not withself.games(game_watcher.rs, Lines 325-335).If manual rescan changes a game from false to true, that vector can remain false. If the game is uninstalled before the next periodic poll, the poll reads false and emits no update. The Games page then keeps showing the game as installed until another manual rescan or watcher restart.
Use one installation-state owner, or make periodic results reconcile against the current UI state instead of an independent delta baseline.