mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-15 17:21:19 +10:00
Also added some type efficiency improvements (using references where possible and added SliceDeque crate) Signed-off-by: quexeky <git@quexeky.dev>
59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
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<AppState>>,
|
|
) -> 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<dyn Downloadable + Send + Sync>);
|
|
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<AppState>>) {
|
|
state.lock().unwrap().download_manager.pause_downloads()
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn resume_game_downloads(state: tauri::State<'_, Mutex<AppState>>) {
|
|
state.lock().unwrap().download_manager.resume_downloads()
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn move_game_in_queue(
|
|
state: tauri::State<'_, Mutex<AppState>>,
|
|
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<AppState>>, meta: DownloadableMetadata) {
|
|
state.lock().unwrap().download_manager.cancel(meta)
|
|
}
|