use crate::api::search_cancellation::SearchCancellation; use crate::api::{Result, TheseusSerializableError}; use theseus::curseforge::{ CurseForgeCapability, CurseForgeCategory, CurseForgeFile, CurseForgeFilesRequest, CurseForgeFilesResponse, CurseForgeFingerprintResult, CurseForgeInstallRequest, CurseForgeInstallResult, CurseForgeManualDownload, CurseForgeManualDownloadImport, CurseForgeManualDownloadScanResult, CurseForgeModpackInstallRequest, CurseForgeModpackInstallResult, CurseForgeProject, CurseForgeRecognitionResult, CurseForgeSearchRequest, UnifiedSearchResponse, }; use theseus::prelude::CacheBehaviour; pub fn init() -> tauri::plugin::TauriPlugin { tauri::plugin::Builder::new("curseforge") .invoke_handler(tauri::generate_handler![ curseforge_capability, curseforge_validate_credentials, curseforge_search_projects, curseforge_get_project, curseforge_get_projects, curseforge_get_description, curseforge_get_files, curseforge_get_file, curseforge_get_files_many, curseforge_get_changelog, curseforge_get_download_url, curseforge_get_categories, curseforge_match_fingerprints, curseforge_install_file, curseforge_preview_install_file, curseforge_update_installed_file, curseforge_switch_installed_file_version, curseforge_recognize_instance_files, curseforge_import_manual_downloads, curseforge_list_pending_manual_downloads, curseforge_import_pending_manual_download_file, curseforge_configure_manual_download_watcher, curseforge_install_modpack, curseforge_update_managed_modpack, ]) .build() } #[tauri::command] pub fn curseforge_capability() -> CurseForgeCapability { theseus::curseforge::capability() } #[tauri::command] pub async fn curseforge_validate_credentials() -> Result { Ok(theseus::curseforge::validate_credentials().await?) } #[tauri::command] pub async fn curseforge_search_projects( request: CurseForgeSearchRequest, request_id: Option, ) -> Result { let Some(request_id) = request_id else { return Ok(theseus::curseforge::search_projects(request).await?); }; let cancellation = SearchCancellation::register(request_id); tokio::select! { result = theseus::curseforge::search_projects(request) => Ok(result?), _ = cancellation.cancelled() => Err(TheseusSerializableError::SearchCancelled( "CurseForge browse search".to_string(), )), } } #[tauri::command] pub async fn curseforge_get_project( project_id: u32, ) -> Result { Ok(theseus::curseforge::get_project(project_id).await?) } #[tauri::command] pub async fn curseforge_get_projects( project_ids: Vec, cache_behaviour: Option, ) -> Result> { Ok(theseus::curseforge::get_projects_with_cache_behaviour( project_ids, cache_behaviour, ) .await?) } #[tauri::command] pub async fn curseforge_get_description(project_id: u32) -> Result { Ok(theseus::curseforge::get_description(project_id).await?) } #[tauri::command] pub async fn curseforge_get_files( project_id: u32, request: CurseForgeFilesRequest, ) -> Result { Ok(theseus::curseforge::get_files(project_id, request).await?) } #[tauri::command] pub async fn curseforge_get_file( project_id: u32, file_id: u32, ) -> Result { Ok(theseus::curseforge::get_file(project_id, file_id).await?) } #[tauri::command] pub async fn curseforge_get_files_many( file_ids: Vec, ) -> Result> { Ok(theseus::curseforge::get_files_many(file_ids).await?) } #[tauri::command] pub async fn curseforge_get_changelog( project_id: u32, file_id: u32, ) -> Result { Ok(theseus::curseforge::get_changelog(project_id, file_id).await?) } #[tauri::command] pub async fn curseforge_get_download_url( project_id: u32, file_id: u32, ) -> Result> { Ok(theseus::curseforge::get_download_url(project_id, file_id).await?) } #[tauri::command] pub async fn curseforge_get_categories( class_id: Option, ) -> Result> { Ok(theseus::curseforge::get_categories(class_id).await?) } #[tauri::command] pub async fn curseforge_match_fingerprints( fingerprints: Vec, ) -> Result { Ok(theseus::curseforge::match_fingerprints(fingerprints).await?) } #[tauri::command] pub async fn curseforge_install_file( request: CurseForgeInstallRequest, ) -> Result { Ok(theseus::curseforge::install_file(request).await?) } #[tauri::command] pub async fn curseforge_preview_install_file( request: CurseForgeInstallRequest, ) -> Result { Ok(theseus::curseforge::preview_install_file(request).await?) } #[tauri::command] pub async fn curseforge_update_installed_file( instance_id: String, relative_path: String, ) -> Result { Ok( theseus::curseforge::update_installed_file( &instance_id, &relative_path, ) .await?, ) } #[tauri::command] pub async fn curseforge_switch_installed_file_version( instance_id: String, relative_path: String, file_id: u32, ) -> Result { Ok(theseus::curseforge::switch_installed_file_version( &instance_id, &relative_path, file_id, ) .await?) } #[tauri::command] pub async fn curseforge_recognize_instance_files( instance_id: String, ) -> Result { Ok(theseus::curseforge::recognize_instance_files(&instance_id).await?) } #[tauri::command] pub async fn curseforge_import_manual_downloads( instance_id: String, scan_directory: Option, ) -> Result { Ok(theseus::curseforge::import_manual_downloads( &instance_id, scan_directory, ) .await?) } #[tauri::command] pub async fn curseforge_list_pending_manual_downloads( instance_id: String, ) -> Result> { Ok( theseus::curseforge::list_pending_manual_downloads(&instance_id) .await?, ) } #[tauri::command] pub async fn curseforge_import_pending_manual_download_file( instance_id: String, project_id: u32, file_id: u32, source_path: std::path::PathBuf, ) -> Result { Ok(theseus::curseforge::import_pending_manual_download_file( &instance_id, project_id, file_id, source_path, ) .await?) } #[tauri::command] pub async fn curseforge_configure_manual_download_watcher( enabled: bool, scan_directory: Option, ) -> Result> { Ok(theseus::curseforge::configure_manual_download_watcher( enabled, scan_directory, ) .await?) } #[tauri::command] pub async fn curseforge_install_modpack( request: CurseForgeModpackInstallRequest, ) -> Result { Ok(theseus::curseforge::install_modpack(request).await?) } #[tauri::command] pub async fn curseforge_update_managed_modpack( instance_id: String, file_id: u32, ) -> Result { Ok(theseus::install::runner::update_managed_curseforge_modpack( instance_id, file_id, ) .await?) }