fix(cache): Bug where games would not remove themselves from the list of installed applications when being uninstalled

This commit is contained in:
quexeky
2025-02-06 19:13:24 +11:00
parent 2690c3019d
commit 9977107374

View File

@ -24,7 +24,7 @@ pub struct FetchGameStruct {
status: GameStatusWithTransient, status: GameStatusWithTransient,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Game { pub struct Game {
id: String, id: String,
@ -114,15 +114,18 @@ pub fn fetch_library_logic_offline(
_state: tauri::State<'_, Mutex<AppState>>, _state: tauri::State<'_, Mutex<AppState>>,
) -> Result<Vec<Game>, RemoteAccessError> { ) -> Result<Vec<Game>, RemoteAccessError> {
let mut games: Vec<Game> = get_cached_object("library")?; let mut games: Vec<Game> = get_cached_object("library")?;
println!("Old games: {:?}", games.len());
let db_handle = borrow_db_checked(); let db_handle = borrow_db_checked();
games.retain(|game| { games.retain(|game| {
println!("Retaining game {}: {}", &game.id, db_handle.applications.installed_game_version.contains_key(&game.id));
db_handle db_handle
.applications .applications
.installed_game_version .installed_game_version
.contains_key(&game.id) .contains_key(&game.id)
}); });
println!("New games: {:?}", games.len());
Ok(games) Ok(games)
} }
@ -244,6 +247,7 @@ pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle)
return; return;
} }
let previous_state = previous_state.unwrap(); let previous_state = previous_state.unwrap();
if let Some((_, install_dir)) = match previous_state { if let Some((_, install_dir)) = match previous_state {
GameDownloadStatus::Installed { GameDownloadStatus::Installed {
version_name, version_name,
@ -260,6 +264,9 @@ pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle)
.transient_statuses .transient_statuses
.entry(meta.clone()) .entry(meta.clone())
.and_modify(|v| *v = ApplicationTransientStatus::Uninstalling {}); .and_modify(|v| *v = ApplicationTransientStatus::Uninstalling {});
db_handle.applications.installed_game_version.remove(&meta.id);
drop(db_handle); drop(db_handle);
let app_handle = app_handle.clone(); let app_handle = app_handle.clone();