diff --git a/crates/lanspread-tauri-deno-ts/src-tauri/src/lib.rs b/crates/lanspread-tauri-deno-ts/src-tauri/src/lib.rs index bb13677..0bee10f 100644 --- a/crates/lanspread-tauri-deno-ts/src-tauri/src/lib.rs +++ b/crates/lanspread-tauri-deno-ts/src-tauri/src/lib.rs @@ -793,6 +793,31 @@ async fn unpack_game(id: &str, sidecar: Command, games_folder: &str) { } } +/// Resolve the bundled catalog database packaged with the Tauri application. +fn resolve_bundled_game_db_path(app_handle: &AppHandle) -> PathBuf { + app_handle + .path() + .resolve("game.db", tauri::path::BaseDirectory::Resource) + .unwrap_or_else(|e| { + log::error!("Failed to resolve game.db resource: {e}"); + panic!("game.db resource is required - cannot continue"); + }) +} + +/// Load the bundled catalog into the in-memory game database used by the UI. +async fn load_bundled_game_db(app_handle: &AppHandle) -> GameDB { + let game_db_path = resolve_bundled_game_db_path(app_handle); + let eti_games = get_games(&game_db_path).await.unwrap_or_else(|e| { + log::error!("Failed to load ETI games: {e}"); + panic!("game.db resource is required - cannot continue"); + }); + + log::info!("Loaded {} ETI games from game.db", eti_games.len()); + + let games: Vec = eti_games.into_iter().map(Into::into).collect(); + GameDB::from(games) +} + #[allow(clippy::too_many_lines)] #[allow(clippy::missing_panics_doc)] #[cfg_attr(mobile, tauri::mobile_entry_point)] @@ -840,35 +865,10 @@ pub fn run() { }; if !games_folder.is_empty() { - // Load ETI games from the game.db resource - this MUST succeed - let game_db_path = - match app_handle_clone - .path() - .resolve("game.db", tauri::path::BaseDirectory::Resource) - { - Ok(path) => { dbg!(&path); path }, - Err(e) => { - log::error!("Failed to resolve game.db resource: {e}"); - panic!("game.db resource is mandatory - cannot continue"); - } - }; - - let eti_games = match get_games(&game_db_path).await { - Ok(games) => { - log::info!("Loaded {} ETI games from game.db", games.len()); - games - } - Err(e) => { - log::error!("Failed to load ETI games: {e}"); - panic!("game.db resource is mandatory - cannot continue"); - } - }; - - // Convert ETI games to GameDB and store in state - let games: Vec = eti_games.into_iter().map(Into::into).collect(); + let game_db = load_bundled_game_db(&app_handle_clone).await; { let state = app_handle_clone.state::(); - *state.games.write().await = GameDB::from(games); + *state.games.write().await = game_db; } refresh_games_list(&app_handle_clone).await;