refactor: extract bundled game database loading
Move the required game.db resource resolution and ETI catalog loading out of Tauri setup into small helpers. The setup closure now describes the startup flow instead of carrying resource-resolution and conversion details inline. This keeps the existing fail-fast behavior for a missing or unreadable bundled catalog, while giving the required resource path and in-memory GameDB conversion clear names. There is no intended user-visible behavior change. Test Plan: - cargo clippy - cargo clippy --benches - cargo clippy --tests - cargo +nightly fmt Refs: none
This commit is contained in:
@@ -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<Game> = 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<Game> = 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::<LanSpreadState>();
|
||||
*state.games.write().await = GameDB::from(games);
|
||||
*state.games.write().await = game_db;
|
||||
}
|
||||
|
||||
refresh_games_list(&app_handle_clone).await;
|
||||
|
||||
Reference in New Issue
Block a user