mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 08:41:21 +10:00
Progress on downloads. Currently working on parsing functions to be run asynchronously
This commit is contained in:
22
src-tauri/src/downloads/downloads.rs
Normal file
22
src-tauri/src/downloads/downloads.rs
Normal file
@ -0,0 +1,22 @@
|
||||
/* GENERAL OUTLINE
|
||||
When downloading any game, the following details must be provided to the server:
|
||||
- Game ID
|
||||
- User token
|
||||
- TBC
|
||||
|
||||
The steps to then download a game are as follows:
|
||||
1. User requests
|
||||
*/
|
||||
use tauri::AppHandle;
|
||||
use crate::auth::generate_authorization_header;
|
||||
use crate::DB;
|
||||
use crate::db::DatabaseImpls;
|
||||
use crate::downloads::manifest::Manifest;
|
||||
|
||||
#[tauri::command]
|
||||
fn download_game(app: AppHandle, game_id: String) -> Result<String, String>{
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
||||
|
||||
3
src-tauri/src/downloads/manifest.rs
Normal file
3
src-tauri/src/downloads/manifest.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub(crate) struct Manifest {
|
||||
|
||||
}
|
||||
2
src-tauri/src/downloads/mod.rs
Normal file
2
src-tauri/src/downloads/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
mod downloads;
|
||||
mod manifest;
|
||||
@ -3,6 +3,8 @@ mod db;
|
||||
mod library;
|
||||
mod remote;
|
||||
mod unpacker;
|
||||
mod downloads;
|
||||
mod utils;
|
||||
|
||||
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
|
||||
use db::{DatabaseInterface, DATA_ROOT_DIR};
|
||||
@ -101,6 +103,8 @@ pub fn run() {
|
||||
// Library
|
||||
fetch_library,
|
||||
fetch_game,
|
||||
// Downloads
|
||||
download_game
|
||||
])
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.setup(|app| {
|
||||
|
||||
44
src-tauri/src/utils.rs
Normal file
44
src-tauri/src/utils.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
use crate::utils::ProgressChecker::Complete;
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum ProgressChecker {
|
||||
Complete,
|
||||
Incomplete
|
||||
}
|
||||
|
||||
// This function is designed to take in any function which does not regularly return a value,
|
||||
// and instead loops over it until it returns "Complete". The current number of iterations
|
||||
// is counted by "progress"
|
||||
pub async fn progress_updater(function: Box<dyn Fn() -> ProgressChecker>, progress: AtomicUsize) {
|
||||
loop {
|
||||
if function() == ProgressChecker::Complete { break }
|
||||
progress.fetch_add(1, Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn threaded_progress_updater<F>(f: F, progress: AtomicUsize, max_threads: usize, instances: usize) -> ProgressChecker
|
||||
where F: Fn() -> ProgressChecker + Send + Clone + Copy + 'static
|
||||
{
|
||||
let mut threads = Vec::new();
|
||||
for instance in 0..instances {
|
||||
let func = tokio::spawn(async move {
|
||||
let res = f();
|
||||
return res
|
||||
});
|
||||
threads.push(func);
|
||||
}
|
||||
let mut completed = ProgressChecker::Incomplete;
|
||||
for thread in threads {
|
||||
if thread.await.unwrap() == Complete {
|
||||
completed = Complete
|
||||
}
|
||||
progress.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
completed
|
||||
}
|
||||
|
||||
fn test() -> ProgressChecker {
|
||||
ProgressChecker::Incomplete
|
||||
}
|
||||
Reference in New Issue
Block a user