game_manager_lib/commands/platforms/
gog.rs1use crate::commands::platforms::core::{
4 format_import_empty, format_import_summary, format_login_success,
5};
6use crate::database::AppState;
7use crate::errors::AppError;
8use crate::sources::gog::GogSource;
9use crate::sources::providers::OAuthGameSource;
10use tauri::{AppHandle, Emitter, State};
11use tracing::{info, warn};
12
13#[tauri::command]
18pub async fn gog_login(app: AppHandle) -> Result<String, AppError> {
19 let source = GogSource::new(app);
20 source.login().await?;
21 Ok(format_login_success("GOG"))
22}
23
24#[tauri::command]
26pub fn gog_logout(app: AppHandle) -> Result<(), AppError> {
27 let source = GogSource::new(app);
28 source.logout()
29}
30
31#[tauri::command]
34pub fn gog_is_authenticated(app: AppHandle) -> Result<bool, AppError> {
35 let source = GogSource::new(app);
36 source.is_authenticated()
37}
38
39#[tauri::command]
43pub async fn import_gog_games(
44 app: AppHandle,
45 state: State<'_, AppState>,
46 gog_games_dir: Option<String>,
47) -> Result<String, AppError> {
48 use crate::commands::platforms::core::persist_source_games;
49 use crate::sources::gog::{detect_installed_games, GogSource};
50 use std::path::Path;
51
52 let source = GogSource::new(app.clone());
53 let mut games = source.fetch_games_detailed().await?;
54
55 if let Some(dir) = gog_games_dir.filter(|s| !s.trim().is_empty()) {
56 let path = Path::new(&dir);
57 if path.exists() && path.is_dir() {
58 detect_installed_games(&mut games, path);
59 } else {
60 warn!("GOG games directory provided but not found: {}", dir);
61 }
62 }
63
64 if games.is_empty() {
65 return Ok(format_import_empty("GOG"));
66 }
67
68 let (inserted, updated, _newly_imported) = persist_source_games(&state, games).await?;
69 let message = format_import_summary("GOG", inserted, updated);
70 info!("{}", message);
71
72 let _ = app.emit("library_updated", ());
73
74 Ok(message)
75}