Skip to main content

game_manager_lib/commands/platforms/
gog.rs

1use crate::commands::platforms::core::{format_login_success, spawn_import};
2use crate::errors::AppError;
3use crate::sources::gog::GogSource;
4use crate::sources::providers::OAuthGameSource;
5use tauri::AppHandle;
6use tracing::warn;
7
8#[tauri::command]
9pub async fn gog_login(app: AppHandle) -> Result<String, AppError> {
10    let source = GogSource::new(app);
11    source.login().await?;
12    Ok(format_login_success("GOG"))
13}
14
15#[tauri::command]
16pub fn gog_logout(app: AppHandle) -> Result<(), AppError> {
17    let source = GogSource::new(app);
18    source.logout()
19}
20
21#[tauri::command]
22pub fn gog_is_authenticated(app: AppHandle) -> Result<bool, AppError> {
23    let source = GogSource::new(app);
24    source.is_authenticated()
25}
26
27#[tauri::command]
28pub async fn import_gog_games(
29    app: AppHandle,
30    gog_games_dir: Option<String>,
31) -> Result<(), AppError> {
32    use crate::sources::gog::{detect_installed_games, GogSource};
33    use std::path::Path;
34
35    spawn_import(app, "GOG", |app| async move {
36        let source = GogSource::new(app);
37        let mut games = source.fetch_games_detailed().await?;
38
39        if let Some(dir) = gog_games_dir.filter(|s| !s.trim().is_empty()) {
40            let path = Path::new(&dir);
41            if path.exists() && path.is_dir() {
42                detect_installed_games(&mut games, path);
43            } else {
44                warn!("GOG games directory provided but not found: {}", dir);
45            }
46        }
47
48        Ok(games)
49    });
50    Ok(())
51}