misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
fix(tray+handoff): tray click toggles window; browser downloads open only their dialog (#520)
9M2PJU70599ffc0a2f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 36780b14..f417ed91 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -51,6 +51,8 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see- The **Download video** window remembers the folder you save into, per **Options → Save to**'s "Change folder for this category on last selected", as **Download File Info** does: it no longer goes back to the Video category's folder each time ([#475](https://github.com/anefzaoui/misterdownloadmanager/issues/475)).- X (Twitter) videos sent from the browser's media list are named after the tab, not the random name of their file on X's video server ([#493](https://github.com/anefzaoui/misterdownloadmanager/issues/493)).- Windows: **Open folder** on a download opens the folder with the file manager set up to open folders (Directory Opus, for example), instead of always starting Windows Explorer. With Explorer it still selects the file ([#446](https://github.com/anefzaoui/misterdownloadmanager/issues/446)).+- Left click on the tray icon now toggles the main window: hidden or minimized shows it again, in front hides it to the tray, and behind other windows brings it forward (it only ever showed it, so clicking while the window was visible did nothing).+- A download started in the browser (a video's download button, a link, a magnet or .torrent) now opens only its dialog when the main window is hidden or minimized, instead of always bringing the full window up.## [0.5.2] - 2026-11-09diff --git a/ROADMAP.md b/ROADMAP.mdindex e374c1e1..f42febb5 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -654,6 +654,9 @@ These ship in a later version, when they're ready.- 🔄 Crash reports: a monitor that cannot open its socket exits, and an unreachable one iscleaned up instead of staying beside MDM: fix in review([#458](https://github.com/anefzaoui/misterdownloadmanager/pull/458))+- 🔄 Left click on the tray icon toggles the main window, and browser downloads open only+ their dialog when the main window is hidden or minimized: fix in review+ ([#520](https://github.com/anefzaoui/misterdownloadmanager/pull/520))## Planneddiff --git a/crates/app/src/app.rs b/crates/app/src/app.rsindex 3add63c1..130a1a12 100644--- a/crates/app/src/app.rs+++ b/crates/app/src/app.rs@@ -369,6 +369,31 @@ fn next_trim(done: u32) -> Duration {/// before it shows minimized.const TRAY_GRACE: Duration = Duration::from_secs(30);+/// How long after the main window loses focus a tray toggle still counts it as in+/// front (#520): clicking the icon makes the taskbar the foreground window first,+/// so `focused` is always false by the time Toggle runs on Windows. Unknown focus+/// (`None`) never counts: unsure means show, never hide.+const TRAY_TOGGLE_GRACE: Duration = Duration::from_millis(500);++/// Whether a tray left-click hides the window instead of showing it: hidden or+/// minimized never hides; a focused window does; an unfocused one does only when+/// it just lost the focus (the click itself took it), else it is behind other+/// windows and comes forward. Unknown focus never hides.+fn tray_toggle_hide(+ hidden: bool,+ minimized: bool,+ focused: Option<bool>,+ since_focused: Option<Duration>,+) -> bool {+ if hidden || minimized {+ return false;+ }+ if focused == Some(true) {+ return true;+ }+ focused == Some(false) && since_focused.is_some_and(|d| d < TRAY_TOGGLE_GRACE)+}+/// Where a start with the session (#226) leaves the window, decided here alone.#[derive(Debug, PartialEq)]enum AtLogin {@@ -589,6 +614,11 @@ pub struct App {/// a real exit under way (closing the window otherwise only hides it, as IDM does).tray: Option<crate::tray::Tray>,tray_limiter: Option<bool>,+ /// When the main window was last seen focused: a tray click steals the focus first+ /// (the taskbar becomes foreground), so a click on a frontmost window reads as+ /// unfocused by the time Toggle runs. Within [`TRAY_TOGGLE_GRACE`] it still counts+ /// as in front.+ tray_last_focused: Option<Instant>,hidden: bool,/// Hidden to the tray: when to hand the window's memory back to the system next (#72), and/// how many times it was since the window hid.@@ -1170,6 +1200,7 @@ impl App {clip_reading: None,tray: None,tray_limiter: None,+ tray_last_focused: None,// Started with the session (#226): hidden from the first frame.hidden: start == crate::Start::Session,trim_when_hidden: (start == crate::Start::Session)@@ -2315,9 +2346,10 @@ impl App {cmd.url = Some(file);}// The browser's download button over a video: the Download video window, looking the- // page up at once.+ // page up at once. The main window stays where it is (hidden, minimized): only the+ // dialog opens, as its window is its own.if let Some(page) = cmd.video_page.as_deref() {- self.show_window(ctx);+ self.show_for_dialog(ctx);let dir = self.settings.category_dir(Category::Video, &self.downloads);crate::videodlg::refresh_ytdlp(&self.rt);let page = page.to_owned();@@ -2336,7 +2368,7 @@ impl App {}// The browser's right-click menu: a page's (or a selection's) links, to tick in Import.if !cmd.links.is_empty() {- self.show_window(ctx);+ self.show_for_dialog(ctx);let found = cmd.links.iter()@@ -2371,7 +2403,7 @@ impl App {&& std::path::Path::new(u.trim_matches('"')).is_file())}) {let m = m.trim().to_owned();- self.show_window(ctx);+ self.show_for_dialog(ctx);self.open_torrent_dialog(Some(m), ctx);return;}@@ -2399,7 +2431,7 @@ impl App {};if !cmd.silent && (torrent(&url) || final_url.as_ref().is_some_and(torrent)) {let parts = self.request_parts(&url, None, &cmd, crate::debrid::browser_started(&cmd));- self.show_window(ctx);+ self.show_for_dialog(ctx);self.open_torrent_dialog_with(Some(url.to_string()),Some(crate::torrents::Remote { url, parts }),@@ -2951,6 +2983,15 @@ impl App {}}+ /// Before a handoff's dialog: the main window stays where it is (hidden, minimized) and+ /// only the dialog opens, as dialogs are windows of their own.+ fn show_for_dialog(&mut self, ctx: &egui::Context) {+ let minimized = ctx.input(|i| i.viewport().minimized == Some(true));+ if !self.hidden && !minimized {+ self.show_window(ctx);+ }+ }+/// Whether the tray icon is shown somewhere (Linux: a tray host is there; asked when the/// window is closed, the host may come and go). On Windows and macOS the icon itself is/// asked: the shell can accept it and still show nothing, and a window hidden with no icon@@ -3054,6 +3095,11 @@ impl App {t.set_downloads(&running);}self.settle_at_login(ctx);+ // When the window was last focused, for Toggle below. Kept every frame:+ // by the time a tray click arrives the taskbar already took the focus.+ if ctx.input(|i| i.viewport().focused) == Some(true) {+ self.tray_last_focused = Some(Instant::now());+ }let cmds = self.tray.as_ref().map(|t| t.poll()).unwrap_or_default();for c in cmds {use crate::tray::TrayCmd;@@ -3063,6 +3109,21 @@ impl App {self.show_window(ctx);continue;}+ TrayCmd::Toggle => {+ let minimized = ctx.input(|i| i.viewport().minimized == Some(true));+ // Behind other windows it still reads as shown: only hide when+ // frontmost, otherwise bring it forward. On Windows the tray+ // click itself takes the focus first, so a window focused just+ // now still counts as in front (#520).+ let focus = ctx.input(|i| i.viewport().focused);+ let since_focused = self.tray_last_focused.map(|t| t.elapsed());+ if tray_toggle_hide(self.hidden, minimized, focus, since_focused) {+ self.hide_to_tray(ctx);+ } else {+ self.show_window(ctx);+ }+ continue;+ }TrayCmd::AddUrl => Cmd::AddUrl,TrayCmd::Batch => Cmd::Batch(false),TrayCmd::LimiterOn => Cmd::LimiterOn,@@ -9132,6 +9193,42 @@ mod at_login_tests {}}+#[cfg(test)]+mod tray_toggle_tests {+ use super::{TRAY_TOGGLE_GRACE, tray_toggle_hide};+ use std::time::Duration;++ /// Left click toggles: hidden or minimized shows; frontmost hides; behind+ /// shows; a click that just took the focus (Windows) still hides (#520).+ #[test]+ fn only_a_frontmost_window_hides() {+ let ms = Duration::from_millis;+ // Hidden or minimized: always shows.+ assert!(!tray_toggle_hide(true, false, Some(false), None));+ assert!(!tray_toggle_hide(false, true, Some(true), None));+ // Frontmost: hides.+ assert!(tray_toggle_hide(false, false, Some(true), None));+ // Behind other windows: shows.+ assert!(!tray_toggle_hide(+ false,+ false,+ Some(false),+ Some(TRAY_TOGGLE_GRACE + ms(1))+ ));+ assert!(!tray_toggle_hide(false, false, Some(false), None));+ // The click stole the focus just now (Windows): still hides.+ assert!(tray_toggle_hide(+ false,+ false,+ Some(false),+ Some(TRAY_TOGGLE_GRACE - ms(1))+ ));+ // Unknown focus: unsure means show, never hide.+ assert!(!tray_toggle_hide(false, false, None, None));+ assert!(!tray_toggle_hide(false, false, None, Some(Duration::ZERO)));+ }+}+#[cfg(test)]mod global_cap_tests {use super::share;diff --git a/crates/app/src/tray.rs b/crates/app/src/tray.rsindex d5e2aaba..4762c137 100644--- a/crates/app/src/tray.rs+++ b/crates/app/src/tray.rs@@ -1,5 +1,6 @@//! The notification-area icon (IDM: "IDM menu pops up when you right click on IDM icon"-//! [IDM-doc]). Left click brings the window back; right click shows the menu. The menu's+//! [IDM-doc]). Left click shows the window again, or hides it there while it shows; right click+//! shows the menu. The menu's//! contents are ours ([unknown] IDM's exact items, lab). Windows, macOS (menu bar) and Linux//! (StatusNotifierItem over D-Bus: KDE, GNOME with its AppIndicator extension).@@ -15,6 +16,9 @@ use tray_icon::{MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIc#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub enum TrayCmd {Show,+ /// Left click on the icon: the window back when hidden or behind other+ /// windows, hidden there when frontmost.+ Toggle,AddUrl,Batch,LimiterOn,@@ -275,7 +279,7 @@ impl Tray {..} = e{- let _ = icon_tx.send(TrayCmd::Show);+ let _ = icon_tx.send(TrayCmd::Toggle);icon_ctx.request_repaint();}}));