game_manager_lib/commands/platforms/
epic.rs1use crate::commands::platforms::core::{format_login_success, spawn_import};
2use crate::errors::AppError;
3use crate::sources::epic::EpicSource;
4use crate::sources::providers::OAuthGameSource;
5use tauri::AppHandle;
6
7#[tauri::command]
8pub async fn epic_login(app: AppHandle) -> Result<String, AppError> {
9 let source = EpicSource::new(app, None);
10 source.login().await?;
11 Ok(format_login_success("Epic"))
12}
13
14#[tauri::command]
15pub fn epic_logout(app: AppHandle) -> Result<(), AppError> {
16 let source = EpicSource::new(app, None);
17 source.logout()
18}
19
20#[tauri::command]
21pub fn epic_is_authenticated(app: AppHandle) -> Result<bool, AppError> {
22 let source = EpicSource::new(app, None);
23 source.is_authenticated()
24}
25
26#[tauri::command]
27pub async fn import_epic_games(
28 app: AppHandle,
29 wine_prefix: Option<String>,
30) -> Result<(), AppError> {
31 let prefix = wine_prefix
32 .filter(|s| !s.trim().is_empty())
33 .map(std::path::PathBuf::from);
34
35 spawn_import(app, "Epic", |app| async move {
36 let source = EpicSource::new(app, prefix);
37 let local_games = source.import_installed().await?;
38
39 let mut games = if source.is_authenticated().unwrap_or(false) {
40 source.fetch_library_detailed().await?
41 } else {
42 Vec::new()
43 };
44
45 crate::sources::epic::merge_local_install_status(&mut games, local_games);
46 Ok(games)
47 });
48 Ok(())
49}