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:
2026-05-16 08:50:51 +02:00
parent fce34c7bd2
commit b5d20c1e72
22 changed files with 1389 additions and 131 deletions
@@ -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",
);
+14 -6
View File
@@ -40,6 +40,7 @@ interface Game {
thumbnail: Uint8Array | number[];
downloaded: boolean;
installed: boolean;
availability: GameAvailability;
install_status: InstallStatus;
eti_game_version?: string;
local_version?: string;
@@ -48,6 +49,12 @@ interface Game {
peer_count: number;
}
enum GameAvailability {
Ready = 'Ready',
Downloading = 'Downloading',
LocalOnly = 'LocalOnly',
}
interface GameThumbnailProps {
gameId: string;
alt: string;
@@ -105,6 +112,7 @@ const mergeGameUpdate = (game: Game, previous?: Game): Game => {
return {
...game,
availability: game.availability ?? (game.downloaded ? GameAvailability.Ready : GameAvailability.LocalOnly),
install_status: installStatus,
status_message: localStateChanged ? undefined : previous?.status_message,
status_level: localStateChanged ? undefined : previous?.status_level,
@@ -289,11 +297,11 @@ const App = () => {
}, [gameDir]);
useEffect(() => {
// Listen for game-unpack-finished events specifically
const setupUnpackListener = async () => {
const unlisten = await listen('game-unpack-finished', (event) => {
// Listen for game-install-finished events specifically
const setupInstallFinishedListener = async () => {
const unlisten = await listen('game-install-finished', (event) => {
const game_id = event.payload as string;
console.log(`🗲 game-unpack-finished ${game_id} event received`);
console.log(`🗲 game-install-finished ${game_id} event received`);
clearCheckingPeersTimeout(game_id);
setGameItems(prev => prev.map(item => item.id === game_id
? {
@@ -316,7 +324,7 @@ const App = () => {
return unlisten;
};
setupUnpackListener();
setupInstallFinishedListener();
}, [gameDir]);
useEffect(() => {
@@ -739,7 +747,7 @@ const App = () => {
<span className="size-text">{(item.size / 1024 / 1024 / 1024).toFixed(1)} GB</span>
</div>
<div className="badges">
{item.installed && !item.downloaded && (
{item.installed && item.availability === GameAvailability.LocalOnly && (
<span className="badge local-only">LocalOnly</span>
)}
{!item.installed && item.downloaded && item.local_version && (