mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 16:51:18 +10:00
feat(download ui): debug queue interface
This commit is contained in:
@ -19,21 +19,6 @@ pub fn download_game(
|
||||
.map_err(|_| "An error occurred while communicating with the download manager.".to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_current_game_download_progress(
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
) -> Result<f64, String> {
|
||||
match state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.download_manager
|
||||
.get_current_game_download_progress()
|
||||
{
|
||||
Some(progress) => Ok(progress),
|
||||
None => Err("Game does not exist".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn cancel_game_download(state: tauri::State<'_, Mutex<AppState>>, game_id: String) {
|
||||
info!("Cancelling game download {}", game_id);
|
||||
@ -54,6 +39,19 @@ 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 get_current_write_speed(state: tauri::State<'_, Mutex<AppState>>) {}
|
||||
|
||||
|
||||
@ -132,19 +132,23 @@ impl DownloadManager {
|
||||
let current_index = get_index_from_id(&mut queue, id).unwrap();
|
||||
let to_move = queue.remove(current_index).unwrap();
|
||||
queue.insert(new_index, to_move);
|
||||
self.command_sender.send(DownloadManagerSignal::Update);
|
||||
}
|
||||
pub fn rearrange(&self, current_index: usize, new_index: usize) {
|
||||
let mut queue = self.edit();
|
||||
let to_move = queue.remove(current_index).unwrap();
|
||||
queue.insert(new_index, to_move);
|
||||
self.command_sender.send(DownloadManagerSignal::Update);
|
||||
}
|
||||
pub fn remove_from_queue(&self, index: usize) {
|
||||
self.edit().remove(index);
|
||||
self.command_sender.send(DownloadManagerSignal::Update);
|
||||
}
|
||||
pub fn remove_from_queue_string(&self, id: String) {
|
||||
let mut queue = self.edit();
|
||||
let current_index = get_index_from_id(&mut queue, id).unwrap();
|
||||
queue.remove(current_index);
|
||||
self.command_sender.send(DownloadManagerSignal::Update);
|
||||
}
|
||||
pub fn pause_downloads(&self) {
|
||||
self.command_sender
|
||||
|
||||
@ -134,7 +134,7 @@ pub fn run() {
|
||||
fetch_game_verion_options,
|
||||
// Downloads
|
||||
download_game,
|
||||
get_current_game_download_progress,
|
||||
move_game_in_queue,
|
||||
cancel_game_download,
|
||||
pause_game_downloads,
|
||||
resume_game_downloads,
|
||||
|
||||
@ -17,7 +17,7 @@ use crate::remote::RemoteAccessError;
|
||||
use crate::{auth::generate_authorization_header, AppState, DB};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct FetchGameStruct {
|
||||
pub struct FetchGameStruct {
|
||||
game: Game,
|
||||
status: DatabaseGameStatus,
|
||||
}
|
||||
@ -67,7 +67,7 @@ pub struct GameVersionOption {
|
||||
// total_size: usize,
|
||||
}
|
||||
|
||||
fn fetch_library_logic(app: AppHandle) -> Result<String, RemoteAccessError> {
|
||||
fn fetch_library_logic(app: AppHandle) -> Result<Vec<Game>, RemoteAccessError> {
|
||||
let base_url = DB.fetch_base_url();
|
||||
let library_url = base_url.join("/api/v1/client/user/library")?;
|
||||
|
||||
@ -102,15 +102,18 @@ fn fetch_library_logic(app: AppHandle) -> Result<String, RemoteAccessError> {
|
||||
|
||||
drop(handle);
|
||||
|
||||
Ok(json!(games.clone()).to_string())
|
||||
Ok(games)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn fetch_library(app: AppHandle) -> Result<String, String> {
|
||||
pub fn fetch_library(app: AppHandle) -> Result<Vec<Game>, String> {
|
||||
fetch_library_logic(app).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn fetch_game_logic(id: String, app: tauri::AppHandle) -> Result<String, RemoteAccessError> {
|
||||
fn fetch_game_logic(
|
||||
id: String,
|
||||
app: tauri::AppHandle,
|
||||
) -> Result<FetchGameStruct, RemoteAccessError> {
|
||||
let state = app.state::<Mutex<AppState>>();
|
||||
let mut state_handle = state.lock().unwrap();
|
||||
|
||||
@ -128,7 +131,7 @@ fn fetch_game_logic(id: String, app: tauri::AppHandle) -> Result<String, RemoteA
|
||||
.clone(),
|
||||
};
|
||||
|
||||
return Ok(json!(data).to_string());
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
let base_url = DB.fetch_base_url();
|
||||
@ -173,11 +176,11 @@ fn fetch_game_logic(id: String, app: tauri::AppHandle) -> Result<String, RemoteA
|
||||
.clone(),
|
||||
};
|
||||
|
||||
return Ok(json!(data).to_string());
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn fetch_game(id: String, app: tauri::AppHandle) -> Result<String, String> {
|
||||
pub fn fetch_game(id: String, app: tauri::AppHandle) -> Result<FetchGameStruct, String> {
|
||||
let result = fetch_game_logic(id, app);
|
||||
|
||||
if result.is_err() {
|
||||
|
||||
Reference in New Issue
Block a user