fix(peer): refresh settled install state after operations
The follow-up review found a few stale lifecycle edges around local game transactions. Recovery could sweep active roots, post-operation refreshes still re-ran full startup recovery, and the UI kept inferring local-only state from downloaded and installed flags instead of the backend availability. This updates the peer lifecycle so startup recovery skips active operations, install/update/uninstall refresh only the affected game after the operation guard is dropped, and path-changing game-directory updates are rejected while operations are active. It also removes the dead UpdateGame command, drops the unused manifest_hash write field while preserving old JSON reads, renames the internal install-finished event, and carries availability through the DB, peer summaries, Tauri refreshes, and the React model. The included follow-up documents record the review source, implementation decisions, and the remaining FOLLOW_UP_2.md work so later commits can stay small instead of reopening the completed plan items. Test Plan: - git diff --check - just fmt - just clippy - just test Follow-up-Plan: FOLLOW_UP_PLAN.md
This commit is contained in:
@@ -9,7 +9,13 @@ use std::{
|
||||
|
||||
use eyre::bail;
|
||||
use lanspread_compat::eti::get_games;
|
||||
use lanspread_db::db::{Game, GameDB, GameFileDescription};
|
||||
use lanspread_db::db::{
|
||||
AVAILABILITY_LOCAL_ONLY,
|
||||
AVAILABILITY_READY,
|
||||
Game,
|
||||
GameDB,
|
||||
GameFileDescription,
|
||||
};
|
||||
use lanspread_peer::{
|
||||
InstallOperation,
|
||||
PeerCommand,
|
||||
@@ -356,6 +362,11 @@ fn update_game_installation_state(game: &mut Game, games_root: &Path) {
|
||||
|
||||
let installed = local_install_is_present(&game_path);
|
||||
game.installed = installed;
|
||||
game.availability = if downloaded {
|
||||
AVAILABILITY_READY.to_string()
|
||||
} else {
|
||||
AVAILABILITY_LOCAL_ONLY.to_string()
|
||||
};
|
||||
|
||||
// Size stays anchored to bundled game.db; skip expensive recalculation.
|
||||
|
||||
@@ -534,6 +545,23 @@ async fn update_game_directory(app_handle: tauri::AppHandle, path: String) -> ta
|
||||
}
|
||||
|
||||
let state = app_handle.state::<LanSpreadState>();
|
||||
let current_path = state.games_folder.read().await.clone();
|
||||
let active_ids = state
|
||||
.active_operations
|
||||
.read()
|
||||
.await
|
||||
.keys()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
if current_path != path && !active_ids.is_empty() {
|
||||
log::warn!(
|
||||
"Rejecting game directory change to {} while UI operations are active for: {}",
|
||||
games_folder.display(),
|
||||
active_ids.join(", ")
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
*state.games_folder.write().await = path;
|
||||
|
||||
ensure_bundled_game_db_loaded(&app_handle).await;
|
||||
@@ -601,6 +629,9 @@ async fn update_local_games_in_db(local_games: Vec<Game>, app: AppHandle) {
|
||||
if let Some(existing_game) = game_db.get_mut_game_by_id(&local_game.id) {
|
||||
existing_game.downloaded = local_game.downloaded;
|
||||
existing_game.installed = local_game.installed;
|
||||
existing_game
|
||||
.availability
|
||||
.clone_from(&local_game.availability);
|
||||
existing_game
|
||||
.local_version
|
||||
.clone_from(&local_game.local_version);
|
||||
@@ -618,6 +649,7 @@ async fn update_local_games_in_db(local_games: Vec<Game>, app: AppHandle) {
|
||||
);
|
||||
game.downloaded = false;
|
||||
game.installed = false;
|
||||
game.availability = AVAILABILITY_LOCAL_ONLY.to_string();
|
||||
game.local_version = None;
|
||||
}
|
||||
}
|
||||
@@ -887,7 +919,7 @@ async fn handle_peer_event(app_handle: &AppHandle, event: PeerEvent) {
|
||||
.remove(&id);
|
||||
emit_game_id_event(
|
||||
app_handle,
|
||||
"game-unpack-finished",
|
||||
"game-install-finished",
|
||||
&id,
|
||||
"PeerEvent::InstallGameFinished",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user