feat: move to native_model to allow for database upgrades

This commit is contained in:
DecDuck
2025-05-15 10:13:24 +10:00
parent 02edb2cbc1
commit 790e8c2afe
24 changed files with 298 additions and 365 deletions

View File

@ -3,7 +3,13 @@ use std::sync::Mutex;
use tauri::{AppHandle, Manager};
use crate::{
database::db::GameVersion, error::{library_error::LibraryError, remote_access_error::RemoteAccessError}, games::library::{fetch_game_logic_offline, fetch_library_logic_offline, get_current_meta, uninstall_game_logic}, offline, AppState
database::models::data::GameVersion,
error::{library_error::LibraryError, remote_access_error::RemoteAccessError},
games::library::{
fetch_game_logic_offline, fetch_library_logic_offline, get_current_meta,
uninstall_game_logic,
},
offline, AppState,
};
use super::{
@ -15,16 +21,29 @@ use super::{
};
#[tauri::command]
pub fn fetch_library(state: tauri::State<'_, Mutex<AppState>>) -> Result<Vec<Game>, RemoteAccessError> {
offline!(state, fetch_library_logic, fetch_library_logic_offline, state)
pub fn fetch_library(
state: tauri::State<'_, Mutex<AppState>>,
) -> Result<Vec<Game>, RemoteAccessError> {
offline!(
state,
fetch_library_logic,
fetch_library_logic_offline,
state
)
}
#[tauri::command]
pub fn fetch_game(
game_id: String,
state: tauri::State<'_, Mutex<AppState>>
state: tauri::State<'_, Mutex<AppState>>,
) -> Result<FetchGameStruct, RemoteAccessError> {
offline!(state, fetch_game_logic, fetch_game_logic_offline, game_id, state)
offline!(
state,
fetch_game_logic,
fetch_game_logic_offline,
game_id,
state
)
}
#[tauri::command]

View File

@ -1,14 +1,11 @@
use crate::auth::generate_authorization_header;
use crate::database::db::{
borrow_db_checked, ApplicationTransientStatus, DatabaseImpls,
GameDownloadStatus,
};
use crate::database::db::borrow_db_checked;
use crate::database::models::data::{ApplicationTransientStatus, DownloadType, DownloadableMetadata, GameDownloadStatus};
use crate::download_manager::download_manager::{DownloadManagerSignal, DownloadStatus};
use crate::download_manager::download_thread_control_flag::{
DownloadThreadControl, DownloadThreadControlFlag,
};
use crate::download_manager::downloadable::Downloadable;
use crate::download_manager::downloadable_metadata::{DownloadType, DownloadableMetadata};
use crate::download_manager::progress_object::{ProgressHandle, ProgressObject};
use crate::error::application_download_error::ApplicationDownloadError;
use crate::error::remote_access_error::RemoteAccessError;
@ -25,7 +22,6 @@ use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use tauri::{AppHandle, Emitter};
use urlencoding::encode;
#[cfg(target_os = "linux")]
use rustix::fs::{fallocate, FallocateFlags};
@ -377,7 +373,10 @@ impl Downloadable for GameDownloadAgent {
error!("error while managing download: {}", error);
let mut handle = DB.borrow_data_mut().unwrap();
handle.applications.transient_statuses.remove(&self.metadata());
handle
.applications
.transient_statuses
.remove(&self.metadata());
}
fn on_complete(&self, app_handle: &tauri::AppHandle) {

View File

@ -7,10 +7,9 @@ use serde::{Deserialize, Serialize};
use tauri::Emitter;
use tauri::{AppHandle, Manager};
use crate::database::db::{borrow_db_checked, borrow_db_mut_checked, save_db, GameVersion};
use crate::database::db::{ApplicationTransientStatus, GameDownloadStatus};
use crate::database::db::{borrow_db_checked, borrow_db_mut_checked, save_db};
use crate::database::models::data::{ApplicationTransientStatus, DownloadableMetadata, GameDownloadStatus, GameVersion};
use crate::download_manager::download_manager::DownloadStatus;
use crate::download_manager::downloadable_metadata::DownloadableMetadata;
use crate::error::library_error::LibraryError;
use crate::error::remote_access_error::RemoteAccessError;
use crate::games::state::{GameStatusManager, GameStatusWithTransient};
@ -438,7 +437,12 @@ pub fn on_game_complete(
Ok(())
}
pub fn push_game_update(app_handle: &AppHandle, game_id: &String, version: Option<GameVersion>, status: GameStatusWithTransient) {
pub fn push_game_update(
app_handle: &AppHandle,
game_id: &String,
version: Option<GameVersion>,
status: GameStatusWithTransient,
) {
app_handle
.emit(
&format!("update_game/{}", game_id),

View File

@ -1,4 +1,4 @@
use crate::database::db::{borrow_db_checked, ApplicationTransientStatus, GameDownloadStatus};
use crate::database::{db::borrow_db_checked, models::data::{ApplicationTransientStatus, GameDownloadStatus}};
pub type GameStatusWithTransient = (
Option<GameDownloadStatus>,