Included in AppStatus (Also trying to link to Issue #1)

This commit is contained in:
quexeky
2024-10-19 14:54:29 +11:00
parent e71e4cf0fa
commit 27d0dcafc7
3 changed files with 14 additions and 4 deletions

View File

@ -1,15 +1,20 @@
use std::sync::Arc;
use std::sync::atomic::AtomicUsize;
use serde::{Deserialize, Serialize};
use versions::Version;
use crate::downloads::progress::ProgressChecker;
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all="camelCase")]
pub struct GameDownload {
id: String,
version: Version,
progress: Arc<AtomicUsize>
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all="camelCase")]
pub struct GameChunkCtx {
chunk_id: usize,
}
impl GameDownload {
@ -22,9 +27,10 @@ impl GameDownload {
}
pub async fn download(&self, max_threads: usize, contexts: Vec<GameChunkCtx>) {
let progress = ProgressChecker::new(Box::new(download_game_chunk), self.progress.clone());
progress.run_contexts_sequentially_async(contexts).await;
progress.run_contexts_parallel_async(contexts, max_threads).await;
}
}
fn download_game_chunk(ctx: GameChunkCtx) {
todo!()
todo!();
// Need to implement actual download logic
}

View File

@ -1,4 +1,4 @@
mod downloads;
mod manifest;
pub mod progress;
mod game_download;
pub mod game_download;

View File

@ -21,6 +21,7 @@ use std::{
};
use tauri_plugin_deep_link::DeepLinkExt;
use crate::db::DatabaseImpls;
use crate::downloads::game_download::GameDownload;
#[derive(Clone, Copy, Serialize)]
pub enum AppStatus {
@ -45,6 +46,7 @@ pub struct AppState {
status: AppStatus,
user: Option<User>,
games: HashMap<String, Game>,
game_downloads: Vec<GameDownload>
}
#[tauri::command]
@ -64,6 +66,7 @@ fn setup() -> AppState {
status: AppStatus::NotConfigured,
user: None,
games: HashMap::new(),
game_downloads: vec![],
};
}
@ -72,6 +75,7 @@ fn setup() -> AppState {
status: auth_result.0,
user: auth_result.1,
games: HashMap::new(),
game_downloads: vec![],
}
}