use std::sync::{Arc, Mutex}; use crate::{ download_manager::{downloadable::Downloadable, downloadable_metadata::DownloadableMetadata}, AppState, }; use super::download_agent::GameDownloadAgent; #[tauri::command] pub fn download_game( game_id: String, game_version: String, install_dir: usize, state: tauri::State<'_, Mutex>, ) -> Result<(), String> { let sender = state.lock().unwrap().download_manager.get_sender(); let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new( game_id, game_version, install_dir, sender, )) as Box); state .lock() .unwrap() .download_manager .queue_download(game_download_agent) .map_err(|_| "An error occurred while communicating with the download manager.".to_string()) } #[tauri::command] pub fn pause_game_downloads(state: tauri::State<'_, Mutex>) { state.lock().unwrap().download_manager.pause_downloads() } #[tauri::command] pub fn resume_game_downloads(state: tauri::State<'_, Mutex>) { state.lock().unwrap().download_manager.resume_downloads() } #[tauri::command] pub fn move_game_in_queue( state: tauri::State<'_, Mutex>, old_index: usize, new_index: usize, ) { state .lock() .unwrap() .download_manager .rearrange(old_index, new_index) } #[tauri::command] pub fn cancel_game(state: tauri::State<'_, Mutex>, meta: DownloadableMetadata) { state.lock().unwrap().download_manager.cancel(meta) }