diff --git a/pages/store/index.vue b/pages/store/index.vue index 1b3ea21..53db899 100644 --- a/pages/store/index.vue +++ b/pages/store/index.vue @@ -19,6 +19,12 @@ > Cancel game download + diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 9d13bce..c67067b 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -298,6 +298,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "atomic-counter" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f447d68cfa5a9ab0c1c862a703da2a65b5ed1b7ce1153c9eb0169506d56019" + [[package]] name = "atomic-waker" version = "1.1.2" @@ -580,33 +586,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "ciborium" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" - -[[package]] -name = "ciborium-ll" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" -dependencies = [ - "ciborium-io", - "half", -] - [[package]] name = "cocoa" version = "0.26.0" @@ -1018,10 +997,9 @@ dependencies = [ name = "drop-app" version = "0.1.0" dependencies = [ - "ciborium", + "atomic-counter", "directories", "env_logger", - "gxhash", "hex", "http", "log", @@ -1033,7 +1011,6 @@ dependencies = [ "rustix", "serde", "serde_json", - "structured-logger", "tauri", "tauri-build", "tauri-plugin-deep-link", @@ -1044,7 +1021,6 @@ dependencies = [ "url", "urlencoding", "uuid", - "versions", "webbrowser", ] @@ -1698,15 +1674,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "gxhash" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09f0c897148ec6ff3ca864b7c886df75e6ba09972d206bd9a89af0c18c992253" -dependencies = [ - "rand 0.8.5", -] - [[package]] name = "h2" version = "0.4.6" @@ -1726,16 +1693,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -2045,15 +2002,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "0.4.8" @@ -2244,10 +2192,6 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -dependencies = [ - "serde", - "value-bag", -] [[package]] name = "mac" @@ -2311,12 +2255,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.8.0" @@ -2430,16 +2368,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "num-conv" version = "0.1.0" @@ -3584,15 +3512,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "serde_fmt" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d4ddca14104cd60529e8c7f7ba71a2c8acd8f7f5cfcdc2faf97eeb7c3010a4" -dependencies = [ - "serde", -] - [[package]] name = "serde_json" version = "1.0.128" @@ -3881,103 +3800,12 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "structured-logger" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16524b1ef57fd2e253216ab20ec44f0dc32b29155a4b3e6bef0a857d8c9f5f08" -dependencies = [ - "log", - "parking_lot", - "serde", - "serde_json", - "tokio", -] - [[package]] name = "subtle" version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" -[[package]] -name = "sval" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf38d1fa2ce984086ea42fb856a9f374d94680a4f796831a7fc868d7f2af1b9" - -[[package]] -name = "sval_buffer" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81682ff859964ca1d7cf3d3d0f9ec7204ea04c2c32acb8cc2cf68ecbd3127354" -dependencies = [ - "sval", - "sval_ref", -] - -[[package]] -name = "sval_dynamic" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a213b93bb4c6f4c9f9b17f2e740e077fd18746bbf7c80c72bbadcac68fa7ee4" -dependencies = [ - "sval", -] - -[[package]] -name = "sval_fmt" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6902c6d3fb52c89206fe0dc93546c0123f7d48b5997fd14e61c9e64ff0b63275" -dependencies = [ - "itoa 1.0.11", - "ryu", - "sval", -] - -[[package]] -name = "sval_json" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a28041ea78cdc394b930ae6b897d36246dc240a29a6edf82d76562487fb0b4" -dependencies = [ - "itoa 1.0.11", - "ryu", - "sval", -] - -[[package]] -name = "sval_nested" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "850346e4b0742a7f2fd2697d703ff80084d0b658f0f2e336d71b8a06abf9b68e" -dependencies = [ - "sval", - "sval_buffer", - "sval_ref", -] - -[[package]] -name = "sval_ref" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824afd97a8919f28a35b0fdea979845cc2ae461a8a3aaa129455cb89c88bb77a" -dependencies = [ - "sval", -] - -[[package]] -name = "sval_serde" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ada7520dd719ed672c786c7db7de4f5230f4d504b0821bd8305cd30ca442315" -dependencies = [ - "serde", - "sval", - "sval_nested", -] - [[package]] name = "swift-rs" version = "1.0.7" @@ -4542,7 +4370,6 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -4887,42 +4714,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "value-bag" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" -dependencies = [ - "value-bag-serde1", - "value-bag-sval2", -] - -[[package]] -name = "value-bag-serde1" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccacf50c5cb077a9abb723c5bcb5e0754c1a433f1e1de89edc328e2760b6328b" -dependencies = [ - "erased-serde", - "serde", - "serde_fmt", -] - -[[package]] -name = "value-bag-sval2" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1785bae486022dfb9703915d42287dcb284c1ee37bd1080eeba78cc04721285b" -dependencies = [ - "sval", - "sval_buffer", - "sval_dynamic", - "sval_fmt", - "sval_json", - "sval_ref", - "sval_serde", -] - [[package]] name = "vcpkg" version = "0.2.15" @@ -4941,17 +4732,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "versions" -version = "6.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25d498b63d1fdb376b4250f39ab3a5ee8d103957346abacd911e2d8b612c139" -dependencies = [ - "itertools", - "nom", - "serde", -] - [[package]] name = "vswhom" version = "0.1.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b5374cc..5b7706a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -29,24 +29,21 @@ tauri = { version = "2.0.0", features = [] } tauri-plugin-shell = "2.0.0" serde = { version = "1", features = ["derive", "rc"] } serde_json = "1" -ciborium = "0.2.2" rayon = "1.10.0" directories = "5.0.1" webbrowser = "1.0.2" url = "2.5.2" tauri-plugin-deep-link = "2" log = "0.4.22" -structured-logger = "1.0.3" hex = "0.4.3" tauri-plugin-dialog = "2" env_logger = "0.11.5" http = "1.1.0" tokio = { version = "1.40.0", features = ["rt", "tokio-macros"] } -versions = { version = "6.3.2", features = ["serde"] } urlencoding = "2.1.3" rustix = "0.38.37" -gxhash = "2.3.0" md5 = "0.7.0" +atomic-counter = "1.0.1" [dependencies.uuid] version = "1.10.0" diff --git a/src-tauri/src/auth.rs b/src-tauri/src/auth.rs index 7d6f4aa..ad0b241 100644 --- a/src-tauri/src/auth.rs +++ b/src-tauri/src/auth.rs @@ -1,6 +1,5 @@ use std::{ env, - fmt::{Display, Formatter}, sync::Mutex, time::{SystemTime, UNIX_EPOCH}, }; @@ -13,7 +12,6 @@ use url::{ParseError, Url}; use crate::{ db::{DatabaseAuth, DatabaseImpls}, - remote::RemoteAccessError, AppState, AppStatus, User, DB, }; diff --git a/src-tauri/src/downloads/download_agent.rs b/src-tauri/src/downloads/download_agent.rs index 9c42135..cae4a83 100644 --- a/src-tauri/src/downloads/download_agent.rs +++ b/src-tauri/src/downloads/download_agent.rs @@ -3,13 +3,14 @@ use crate::db::{DatabaseImpls, DATA_ROOT_DIR}; use crate::downloads::download_logic; use crate::downloads::manifest::{DropDownloadContext, DropManifest}; use crate::downloads::progress::ProgressChecker; -use crate::{AppState, DB}; +use crate::DB; +use atomic_counter::RelaxedCounter; use log::info; use rustix::fs::{fallocate, FallocateFlags}; use serde::{Deserialize, Serialize}; use std::fs::{create_dir_all, File}; use std::path::Path; -use std::sync::atomic::{AtomicBool, AtomicUsize}; +use std::sync::atomic::AtomicBool; use std::sync::{Arc, Mutex}; use urlencoding::encode; @@ -18,7 +19,7 @@ pub struct GameDownloadAgent { pub version: String, state: Mutex, contexts: Mutex>, - progress: ProgressChecker, + pub progress: ProgressChecker, pub manifest: Mutex>, pub callback: Arc, } @@ -57,8 +58,9 @@ impl GameDownloadAgent { callback: callback.clone(), progress: ProgressChecker::new( Box::new(download_logic::download_game_chunk), - Arc::new(AtomicUsize::new(0)), + Arc::new(RelaxedCounter::new(0)), callback, + 0, ), contexts: Mutex::new(Vec::new()), } @@ -119,6 +121,13 @@ impl GameDownloadAgent { } let manifest_download = response.json::().unwrap(); + let length = manifest_download + .values() + .map(|chunk| { + return chunk.lengths.iter().sum::(); + }) + .sum::(); + self.progress.set_capacity(length); if let Ok(mut manifest) = self.manifest.lock() { *manifest = Some(manifest_download) } else { diff --git a/src-tauri/src/downloads/download_commands.rs b/src-tauri/src/downloads/download_commands.rs index dcd58d0..064bc55 100644 --- a/src-tauri/src/downloads/download_commands.rs +++ b/src-tauri/src/downloads/download_commands.rs @@ -60,7 +60,7 @@ pub async fn start_game_downloads( } }); info!("Spawned download"); - return Ok(()); + Ok(()) } pub fn start_game_download( @@ -104,5 +104,17 @@ pub async fn stop_specific_game_download( info!("Stopping callback"); callback.store(true, Ordering::Release); - return Ok(()); + Ok(()) +} + +#[tauri::command] +pub async fn get_game_download_progress( + state: tauri::State<'_, Mutex>, + game_id: String, +) -> Result { + let lock = state.lock().unwrap(); + let download_agent = lock.game_downloads.get(&game_id).unwrap(); + let progress = download_agent.progress.get_progress_percentage(); + info!("{}", progress); + Ok(progress) } diff --git a/src-tauri/src/downloads/download_logic.rs b/src-tauri/src/downloads/download_logic.rs index 13866a5..121a844 100644 --- a/src-tauri/src/downloads/download_logic.rs +++ b/src-tauri/src/downloads/download_logic.rs @@ -2,14 +2,12 @@ use crate::auth::generate_authorization_header; use crate::db::DatabaseImpls; use crate::downloads::manifest::DropDownloadContext; use crate::DB; -use gxhash::{gxhash128, GxHasher}; -use log::info; +use atomic_counter::{AtomicCounter, RelaxedCounter}; +use log::{error, info}; use md5::{Context, Digest}; -use reqwest::blocking::Response; use std::{ fs::{File, OpenOptions}, - hash::Hasher, - io::{self, BufReader, BufWriter, Error, ErrorKind, Read, Seek, SeekFrom, Write}, + io::{self, BufWriter, Error, ErrorKind, Seek, SeekFrom, Write}, path::PathBuf, sync::{ atomic::{AtomicBool, Ordering}, @@ -22,13 +20,15 @@ pub struct DropFileWriter { file: File, hasher: Context, callback: Arc, + progress: Arc, } impl DropFileWriter { - fn new(path: PathBuf, callback: Arc) -> Self { + fn new(path: PathBuf, callback: Arc, progress: Arc) -> Self { Self { file: OpenOptions::new().write(true).open(path).unwrap(), hasher: Context::new(), callback, + progress, } } fn finish(mut self) -> io::Result { @@ -45,6 +45,8 @@ impl Write for DropFileWriter { "Interrupt command recieved", )); } + let len = buf.len(); + self.progress.add(len); //info!("Writing data to writer"); self.hasher.write_all(buf).unwrap(); @@ -61,7 +63,11 @@ impl Seek for DropFileWriter { self.file.seek(pos) } } -pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc) { +pub fn download_game_chunk( + ctx: DropDownloadContext, + callback: Arc, + progress: Arc, +) { if callback.load(Ordering::Acquire) { info!("Callback stopped download at start"); return; @@ -88,7 +94,7 @@ pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc) .send() .unwrap(); - let mut file: DropFileWriter = DropFileWriter::new(ctx.path, callback); + let mut file: DropFileWriter = DropFileWriter::new(ctx.path, callback, progress); if ctx.offset != 0 { file.seek(SeekFrom::Start(ctx.offset)) @@ -98,15 +104,22 @@ pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc) // Writing everything to disk directly is probably slightly faster because it balances out the writes, // but this is better than the performance loss from constantly reading the callbacks - //let mut writer = BufWriter::with_capacity(1024 * 1024, file); + let mut writer = BufWriter::with_capacity(1024 * 1024, file); //copy_to_drop_file_writer(&mut response, &mut file); - match io::copy(&mut response, &mut file) { + match io::copy(&mut response, &mut writer) { Ok(_) => {} Err(e) => { info!("Copy errored with error {}", e) } } + let file = match writer.into_inner() { + Ok(file) => file, + Err(_) => { + error!("Failed to acquire writer from BufWriter"); + return; + } + }; let res = hex::encode(file.finish().unwrap().0); if res != ctx.checksum { @@ -118,24 +131,3 @@ pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc) // stream.flush().unwrap(); } - -pub fn copy_to_drop_file_writer(response: &mut Response, writer: &mut DropFileWriter) { - loop { - info!("Writing to file writer"); - let mut buf = [0u8; 1024]; - response.read(&mut buf).unwrap(); - match writer.write_all(&buf) { - Ok(_) => {} - Err(e) => match e.kind() { - ErrorKind::Interrupted => { - info!("Interrupted"); - return; - } - _ => { - println!("{}", e); - return; - } - }, - } - } -} diff --git a/src-tauri/src/downloads/manifest.rs b/src-tauri/src/downloads/manifest.rs index 391c45d..2bb1552 100644 --- a/src-tauri/src/downloads/manifest.rs +++ b/src-tauri/src/downloads/manifest.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::fs::File; use std::path::PathBuf; -use std::sync::{Arc, Mutex}; pub type DropManifest = HashMap; #[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] diff --git a/src-tauri/src/downloads/progress.rs b/src-tauri/src/downloads/progress.rs index 18ea179..720a05e 100644 --- a/src-tauri/src/downloads/progress.rs +++ b/src-tauri/src/downloads/progress.rs @@ -1,15 +1,17 @@ +use atomic_counter::{AtomicCounter, RelaxedCounter}; use log::info; use rayon::ThreadPoolBuilder; -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use std::sync::Arc; +use std::sync::atomic::AtomicBool; +use std::sync::{Arc, Mutex}; pub struct ProgressChecker where T: 'static + Send + Sync, { - counter: Arc, - f: Arc) + Send + Sync + 'static>>, + counter: Arc, + f: Arc, Arc) + Send + Sync + 'static>>, callback: Arc, + capacity: Mutex, } impl ProgressChecker @@ -17,22 +19,25 @@ where T: Send + Sync, { pub fn new( - f: Box) + Send + Sync + 'static>, - counter_reference: Arc, + f: Box, Arc) + Send + Sync + 'static>, + counter: Arc, callback: Arc, + capacity: usize, ) -> Self { Self { f: f.into(), - counter: counter_reference, + counter, callback, + capacity: capacity.into(), } } + #[allow(dead_code)] pub fn run_contexts_sequentially(&self, contexts: Vec) { for context in contexts { - (self.f)(context, self.callback.clone()); - self.counter.fetch_add(1, Ordering::Release); + (self.f)(context, self.callback.clone(), self.counter.clone()); } } + #[allow(dead_code)] pub fn run_contexts_parallel_background(&self, contexts: Vec, max_threads: usize) { let threads = ThreadPoolBuilder::new() // If max_threads == 0, then the limit will be determined @@ -43,8 +48,9 @@ where for context in contexts { let callback = self.callback.clone(); + let counter = self.counter.clone(); let f = self.f.clone(); - threads.spawn(move || f(context, callback)); + threads.spawn(move || f(context, callback, counter)); } } pub fn run_context_parallel(&self, contexts: Vec, max_threads: usize) { @@ -56,20 +62,25 @@ where threads.scope(|s| { for context in contexts { let callback = self.callback.clone(); + let counter = self.counter.clone(); let f = self.f.clone(); s.spawn(move |_| { info!("Running thread"); - f(context, callback) + f(context, callback, counter) }); } }); info!("Concluded scope"); } + pub fn set_capacity(&self, capacity: usize) { + let mut lock = self.capacity.lock().unwrap(); + *lock = capacity; + } pub fn get_progress(&self) -> usize { - self.counter.load(Ordering::Relaxed) + self.counter.get() } // I strongly dislike type casting in my own code, so I've shovelled it into here - pub fn get_progress_percentage>(&self, capacity: C) -> f64 { - (self.get_progress() as f64) / (capacity.into()) + pub fn get_progress_percentage(&self) -> f64 { + (self.get_progress() as f64) / (*self.capacity.lock().unwrap() as f64) } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7472648..923a77d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -11,7 +11,8 @@ use crate::downloads::download_agent::GameDownloadAgent; use auth::{auth_initiate, generate_authorization_header, recieve_handshake}; use db::{DatabaseInterface, DATA_ROOT_DIR}; use downloads::download_commands::{ - queue_game_download, start_game_downloads, stop_specific_game_download, + get_game_download_progress, queue_game_download, start_game_downloads, + stop_specific_game_download, }; use env_logger::Env; use http::{header::*, response::Builder as ResponseBuilder}; @@ -96,6 +97,7 @@ pub fn run() { let mut builder = tauri::Builder::default().plugin(tauri_plugin_dialog::init()); #[cfg(desktop)] + #[allow(unused_variables)] { builder = builder.plugin(tauri_plugin_single_instance::init(|_app, argv, _cwd| { // when defining deep link schemes at runtime, you must also check `argv` here @@ -119,7 +121,8 @@ pub fn run() { // Downloads queue_game_download, start_game_downloads, - stop_specific_game_download + stop_specific_game_download, + get_game_download_progress ]) .plugin(tauri_plugin_shell::init()) .setup(|app| { diff --git a/src-tauri/src/library.rs b/src-tauri/src/library.rs index 80e4134..a63973d 100644 --- a/src-tauri/src/library.rs +++ b/src-tauri/src/library.rs @@ -6,7 +6,6 @@ use tauri::{AppHandle, Manager}; use crate::db::DatabaseGameStatus; use crate::db::DatabaseImpls; -use crate::remote::RemoteAccessError; use crate::{auth::generate_authorization_header, AppState, DB}; #[derive(serde::Serialize)] diff --git a/src-tauri/src/tests/progress_tests.rs b/src-tauri/src/tests/progress_tests.rs index a3c8e5f..1d2df40 100644 --- a/src-tauri/src/tests/progress_tests.rs +++ b/src-tauri/src/tests/progress_tests.rs @@ -1,23 +1,25 @@ +use atomic_counter::RelaxedCounter; + use crate::downloads::progress::ProgressChecker; -use std::sync::atomic::{AtomicBool, AtomicUsize}; +use std::sync::atomic::AtomicBool; use std::sync::Arc; #[test] fn test_progress_sequentially() { - let counter = Arc::new(AtomicUsize::new(0)); + let counter = Arc::new(RelaxedCounter::new(0)); let callback = Arc::new(AtomicBool::new(false)); - let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback); + let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback, 100); p.run_contexts_sequentially((1..100).collect()); - println!("Progress: {}", p.get_progress_percentage(100)); + println!("Progress: {}", p.get_progress_percentage()); } #[test] fn test_progress_parallel() { - let counter = Arc::new(AtomicUsize::new(0)); + let counter = Arc::new(RelaxedCounter::new(0)); let callback = Arc::new(AtomicBool::new(false)); - let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback); + let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback, 100); p.run_contexts_parallel_background((1..100).collect(), 10); } -fn test_fn(int: usize, callback: Arc) { +fn test_fn(int: usize, _callback: Arc, _counter: Arc) { println!("{}", int); }