feat: Download resuming

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-06-22 13:01:18 +10:00
parent fd61903130
commit 8dfb96406f
2 changed files with 14 additions and 8 deletions

View File

@ -32,7 +32,7 @@
@uninstall="() => uninstall()" @uninstall="() => uninstall()"
@kill="() => kill()" @kill="() => kill()"
@options="() => (configureModalOpen = true)" @options="() => (configureModalOpen = true)"
@resume="() => console.log('resume')" @resume="() => resumeDownload()"
:status="status" :status="status"
/> />
<a <a
@ -536,7 +536,7 @@ async function install() {
async function resumeDownload() { async function resumeDownload() {
try { try {
await invoke("resume_download", { game_id: game.value.id, version: status.value.version_name!, install_dir: status.value.install_dir! }) await invoke("resume_download", { gameId: game.value.id })
} }
catch(e) { catch(e) {
console.error(e) console.error(e)

View File

@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex}; use std::{path::PathBuf, sync::{Arc, Mutex}};
use crate::{ use crate::{
database::db::borrow_db_checked, download_manager::{download_manager::DownloadManagerSignal, downloadable::Downloadable}, error::download_manager_error::DownloadManagerError, AppState database::{db::borrow_db_checked, models::data::GameDownloadStatus}, download_manager::{download_manager::DownloadManagerSignal, downloadable::Downloadable}, error::download_manager_error::DownloadManagerError, AppState
}; };
use super::download_agent::GameDownloadAgent; use super::download_agent::GameDownloadAgent;
@ -30,14 +30,20 @@ pub fn download_game(
#[tauri::command] #[tauri::command]
pub fn resume_download( pub fn resume_download(
game_id: String, game_id: String,
version: String,
install_dir: String,
state: tauri::State<'_, Mutex<AppState>>, state: tauri::State<'_, Mutex<AppState>>,
) -> Result<(), DownloadManagerError<DownloadManagerSignal>> { ) -> Result<(), DownloadManagerError<DownloadManagerSignal>> {
let s = borrow_db_checked().applications.game_statuses.get(&game_id).unwrap().clone();
let (version_name, install_dir) = match s {
GameDownloadStatus::Remote { } => unreachable!(),
GameDownloadStatus::SetupRequired { .. } => unreachable!(),
GameDownloadStatus::Installed { .. } => unreachable!(),
GameDownloadStatus::PartiallyInstalled { version_name, install_dir } => (version_name, install_dir),
};
let sender = state.lock().unwrap().download_manager.get_sender(); let sender = state.lock().unwrap().download_manager.get_sender();
let parent_dir: PathBuf = install_dir.into();
let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new( let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new(
game_id, version, install_dir.into(), sender game_id, version_name.clone(), parent_dir.parent().unwrap().to_path_buf(), sender
)) as Box<dyn Downloadable + Send + Sync>); )) as Box<dyn Downloadable + Send + Sync>);
Ok(state.lock().unwrap().download_manager.queue_download(game_download_agent)?) Ok(state.lock().unwrap().download_manager.queue_download(game_download_agent)?)
} }