diff --git a/composables/game.ts b/composables/game.ts
index 0d247e1..28a26fb 100644
--- a/composables/game.ts
+++ b/composables/game.ts
@@ -46,9 +46,21 @@ export const useGame = async (gameId: string) => {
listen(`update_game/${gameId}`, (event) => {
const payload: {
status: SerializedGameStatus;
+ version?: GameVersion;
} = event.payload as any;
console.log(payload.status);
gameStatusRegistry[gameId].value = parseStatus(payload.status);
+
+ /**
+ * I am not super happy about this.
+ *
+ * This will mean that we will still have a version assigned if we have a game installed then uninstall it.
+ * It is necessary because a flag to check if we should overwrite seems excessive, and this function gets called
+ * on transient state updates.
+ */
+ if (payload.version) {
+ gameRegistry[gameId].version = payload.version;
+ }
});
}
}
diff --git a/pages/library/[id]/index.vue b/pages/library/[id]/index.vue
index 1d82834..bfb397a 100644
--- a/pages/library/[id]/index.vue
+++ b/pages/library/[id]/index.vue
@@ -369,7 +369,7 @@
-
+
, &DownloadableMetadata)>(
- app_handle: &AppHandle,
- meta: DownloadableMetadata,
- setter: F,
-) {
- let mut db_handle = borrow_db_mut_checked();
- setter(&mut db_handle, &meta);
- drop(db_handle);
- save_db();
-
- let status = GameStatusManager::fetch_state(&meta.id);
-
- push_game_update(app_handle, &meta.id, status);
-}
// TODO: Make the error relelvant rather than just assume that it's a Deserialize error
fn handle_invalid_database(
_e: RustbreakError,
diff --git a/src-tauri/src/games/downloads/download_agent.rs b/src-tauri/src/games/downloads/download_agent.rs
index dce5043..ad50ed1 100644
--- a/src-tauri/src/games/downloads/download_agent.rs
+++ b/src-tauri/src/games/downloads/download_agent.rs
@@ -1,6 +1,6 @@
use crate::auth::generate_authorization_header;
use crate::database::db::{
- borrow_db_checked, set_game_status, ApplicationTransientStatus, DatabaseImpls,
+ borrow_db_checked, ApplicationTransientStatus, DatabaseImpls,
GameDownloadStatus,
};
use crate::download_manager::download_manager::{DownloadManagerSignal, DownloadStatus};
@@ -99,6 +99,7 @@ impl GameDownloadAgent {
push_game_update(
app_handle,
&self.metadata().id,
+ None,
(
None,
Some(ApplicationTransientStatus::Downloading {
@@ -375,9 +376,8 @@ impl Downloadable for GameDownloadAgent {
error!("error while managing download: {}", error);
- set_game_status(app_handle, self.metadata(), |db_handle, meta| {
- db_handle.applications.transient_statuses.remove(meta);
- });
+ let mut handle = DB.borrow_data_mut().unwrap();
+ handle.applications.transient_statuses.remove(&self.metadata());
}
fn on_complete(&self, app_handle: &tauri::AppHandle) {
@@ -399,6 +399,7 @@ impl Downloadable for GameDownloadAgent {
GameUpdateEvent {
game_id: meta.id.clone(),
status: (Some(GameDownloadStatus::Remote {}), None),
+ version: None,
},
)
.unwrap();
diff --git a/src-tauri/src/games/library.rs b/src-tauri/src/games/library.rs
index 425f01e..270e6a5 100644
--- a/src-tauri/src/games/library.rs
+++ b/src-tauri/src/games/library.rs
@@ -48,6 +48,7 @@ pub struct GameUpdateEvent {
Option,
Option,
),
+ pub version: Option,
}
#[derive(Serialize, Clone)]
@@ -291,6 +292,7 @@ pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle)
push_game_update(
app_handle,
&meta.id,
+ None,
(None, Some(ApplicationTransientStatus::Uninstalling {})),
);
@@ -346,6 +348,7 @@ pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle)
push_game_update(
&app_handle,
&meta.id,
+ None,
(Some(GameDownloadStatus::Remote {}), None),
);
}
@@ -385,7 +388,7 @@ pub fn on_game_complete(
)?
.send()?;
- let data: GameVersion = response.json()?;
+ let game_version: GameVersion = response.json()?;
let mut handle = borrow_db_mut_checked();
handle
@@ -393,7 +396,7 @@ pub fn on_game_complete(
.game_versions
.entry(meta.id.clone())
.or_default()
- .insert(meta.version.clone().unwrap(), data.clone());
+ .insert(meta.version.clone().unwrap(), game_version.clone());
handle
.applications
.installed_game_version
@@ -402,7 +405,7 @@ pub fn on_game_complete(
drop(handle);
save_db();
- let status = if data.setup_command.is_empty() {
+ let status = if game_version.setup_command.is_empty() {
GameDownloadStatus::Installed {
version_name: meta.version.clone().unwrap(),
install_dir,
@@ -427,6 +430,7 @@ pub fn on_game_complete(
GameUpdateEvent {
game_id: meta.id.clone(),
status: (Some(status), None),
+ version: Some(game_version),
},
)
.unwrap();
@@ -434,13 +438,14 @@ pub fn on_game_complete(
Ok(())
}
-pub fn push_game_update(app_handle: &AppHandle, game_id: &String, status: GameStatusWithTransient) {
+pub fn push_game_update(app_handle: &AppHandle, game_id: &String, version: Option, status: GameStatusWithTransient) {
app_handle
.emit(
&format!("update_game/{}", game_id),
GameUpdateEvent {
game_id: game_id.clone(),
status,
+ version,
},
)
.unwrap();
@@ -464,7 +469,6 @@ pub fn update_game_configuration(
.get(&game_id)
.ok_or(LibraryError::MetaNotFound(game_id))?;
-
let id = installed_version.id.clone();
let version = installed_version.version.clone().unwrap();
diff --git a/src-tauri/src/process/process_manager.rs b/src-tauri/src/process/process_manager.rs
index 53f46d7..2bcfd01 100644
--- a/src-tauri/src/process/process_manager.rs
+++ b/src-tauri/src/process/process_manager.rs
@@ -134,7 +134,7 @@ impl ProcessManager<'_> {
let status = GameStatusManager::fetch_state(&game_id);
- push_game_update(&self.app_handle, &game_id, status);
+ push_game_update(&self.app_handle, &game_id, None, status);
// TODO better management
}
@@ -296,6 +296,7 @@ impl ProcessManager<'_> {
push_game_update(
&self.app_handle,
&meta.id,
+ None,
(None, Some(ApplicationTransientStatus::Running {})),
);