game_manager_lib/commands/platforms/
ubisoft.rs1use crate::commands::platforms::core::{
10 format_import_empty, format_import_summary, persist_source_games,
11};
12use crate::database::AppState;
13use crate::errors::AppError;
14use tauri::{AppHandle, Emitter, State};
15use tracing::info;
16
17#[tauri::command]
18pub async fn import_ubisoft_games(
19 app: AppHandle,
20 state: State<'_, AppState>,
21 wine_prefix: Option<String>,
22) -> Result<String, AppError> {
23 use crate::sources::providers::GameSource;
24 use crate::sources::ubisoft::UbisoftSource;
25
26 let prefix = wine_prefix
27 .filter(|s| !s.trim().is_empty())
28 .map(std::path::PathBuf::from);
29
30 let source = UbisoftSource::new(true, prefix);
31 let games = source.fetch_games().await?;
32
33 if games.is_empty() {
34 return Ok(format_import_empty("Ubisoft"));
35 }
36
37 let (inserted, updated, newly_imported) = persist_source_games(&state, games).await?;
38 let message = format_import_summary("Ubisoft", inserted, updated);
39 info!("{}", message);
40
41 if !newly_imported.is_empty() {
42 let app_clone = app.clone();
43 tauri::async_runtime::spawn(async move {
44 crate::commands::metadata::enrichment::enrich_newly_imported(app_clone, newly_imported)
45 .await;
46 });
47 }
48
49 let _ = app.emit("library_updated", ());
50
51 Ok(message)
52}