game_manager_lib/commands/platforms/
heroic.rs1use crate::commands::platforms::core::{
4 format_import_empty, format_import_summary, persist_source_games,
5};
6use crate::database::AppState;
7use crate::errors::AppError;
8use tauri::{AppHandle, Emitter, State};
9use tracing::info;
10
11#[tauri::command]
12pub async fn import_heroic_games(
13 app: AppHandle,
14 state: State<'_, AppState>,
15 heroic_config_path: Option<String>,
16) -> Result<String, AppError> {
17 use crate::sources::heroic::HeroicSource;
18
19 let config_path = heroic_config_path
20 .filter(|s| !s.trim().is_empty())
21 .map(std::path::PathBuf::from);
22
23 let games = HeroicSource::import_installed(config_path).await?;
24
25 if games.is_empty() {
26 return Ok(format_import_empty("Heroic"));
27 }
28
29 let (inserted, updated, _newly_imported) = persist_source_games(&state, games).await?;
30 let message = format_import_summary("Heroic", inserted, updated);
31 info!("{}", message);
32
33 let _ = app.emit("library_updated", ());
34
35 Ok(message)
36}