mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 08:41:21 +10:00
commit0f48f3fb44Author: quexeky <git@quexeky.dev> Date: Sun Oct 12 19:35:04 2025 +1100 chore: Run cargo clippy && cargo fmt Signed-off-by: quexeky <git@quexeky.dev> commit974666efe2Author: quexeky <git@quexeky.dev> Date: Sun Oct 12 19:17:40 2025 +1100 refactor: Finish refactor Signed-off-by: quexeky <git@quexeky.dev> commit9e1bf9852fAuthor: quexeky <git@quexeky.dev> Date: Sun Oct 12 18:33:43 2025 +1100 refactor: Builds, but some logic still left to move back Signed-off-by: quexeky <git@quexeky.dev> commit5d22b883d5Author: quexeky <git@quexeky.dev> Date: Sun Oct 12 17:04:27 2025 +1100 refactor: Improvements to src-tauri Signed-off-by: quexeky <git@quexeky.dev> commit62a2561539Author: quexeky <git@quexeky.dev> Date: Sat Oct 11 09:51:04 2025 +1100 fix: Remote tauri dependency from process Signed-off-by: quexeky <git@quexeky.dev> commit59f040bc8bAuthor: quexeky <git@quexeky.dev> Date: Thu Oct 9 07:46:17 2025 +1100 chore: Major refactoring Still needs a massive go-over because there shouldn't be anything referencing tauri in any of the workspaces except the original one. Process manager has been refactored as an example Signed-off-by: quexeky <git@quexeky.dev> Signed-off-by: quexeky <git@quexeky.dev>
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
use std::sync::{
|
|
Arc,
|
|
atomic::{AtomicUsize, Ordering},
|
|
};
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct RollingProgressWindow<const S: usize> {
|
|
window: Arc<[AtomicUsize; S]>,
|
|
current: Arc<AtomicUsize>,
|
|
}
|
|
impl<const S: usize> Default for RollingProgressWindow<S> {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
impl<const S: usize> RollingProgressWindow<S> {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
window: Arc::new([(); S].map(|()| AtomicUsize::new(0))),
|
|
current: Arc::new(AtomicUsize::new(0)),
|
|
}
|
|
}
|
|
pub fn update(&self, kilobytes_per_second: usize) {
|
|
let index = self.current.fetch_add(1, Ordering::SeqCst);
|
|
let current = &self.window[index % S];
|
|
current.store(kilobytes_per_second, Ordering::SeqCst);
|
|
}
|
|
pub fn get_average(&self) -> usize {
|
|
let current = self.current.load(Ordering::SeqCst);
|
|
let valid = self
|
|
.window
|
|
.iter()
|
|
.enumerate()
|
|
.filter(|(i, _)| i < ¤t)
|
|
.map(|(_, x)| x.load(Ordering::Acquire))
|
|
.collect::<Vec<usize>>();
|
|
let amount = valid.len();
|
|
let sum = valid.into_iter().sum::<usize>();
|
|
|
|
sum / amount
|
|
}
|
|
pub fn reset(&self) {
|
|
self.window
|
|
.iter()
|
|
.for_each(|x| x.store(0, Ordering::Release));
|
|
self.current.store(0, Ordering::Release);
|
|
}
|
|
}
|