Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

fix: add LAST_ACTIVE tracking for total active downloads in compute_total_active function

Tonho2acbd28f2c46
diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs
index b538c3b1..76b4ac70 100644
--- a/src-tauri/src/tray.rs
+++ b/src-tauri/src/tray.rs
@@ -1,3 +1,4 @@
+use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::OnceLock;
use tauri::{
@@ -7,6 +8,7 @@ use tauri::{
};
static DOWNLOADS_ITEM: OnceLock<MenuItem<Wry>> = OnceLock::new();
+static LAST_ACTIVE: AtomicU32 = AtomicU32::new(0);
pub fn setup(app: &AppHandle) -> tauri::Result<()> {
let open_item = MenuItemBuilder::with_id("open", "OmniGet").build(app)?;
@@ -62,6 +64,27 @@ pub fn update_active_count(_app: &AppHandle, count: u32) {
}
}
+pub fn compute_total_active(app: &AppHandle) -> u32 {
+ let state = app.state::<crate::AppState>();
+
+ let queue_count = match state.download_queue.try_lock() {
+ Ok(q) => q.active_count(),
+ Err(_) => return LAST_ACTIVE.load(Ordering::Relaxed),
+ };
+
+ let tg_count = match state.active_generic_downloads.try_lock() {
+ Ok(active) => active
+ .values()
+ .filter(|(key, _)| key.starts_with("tg-batch:"))
+ .count() as u32,
+ Err(_) => return LAST_ACTIVE.load(Ordering::Relaxed),
+ };
+
+ let total = queue_count + tg_count;
+ LAST_ACTIVE.store(total, Ordering::Relaxed);
+ total
+}
+
fn active_label(count: u32) -> String {
if count == 0 {
"No active downloads".into()