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
A window closed with its × no longer turns black first (#207) (#209)
Ahmed Nefzaoui65b648b15fac
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1f4bb83a..d3144374 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -394,6 +394,11 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see### Fixed+- **A window closed with its title bar's × no longer turns black first**+ ([#207](https://github.com/anefzaoui/misterdownloadmanager/issues/207)): every dialog and the+ progress window turned black for a moment when closed with the × or Alt+F4, rather than with+ Esc or one of its buttons: one to several seconds on Linux, a few hundredths of a second on+ Windows. The window now keeps its contents until it goes.- **A freeze while MDM handles a command is reported again**([#202](https://github.com/anefzaoui/misterdownloadmanager/issues/202)): since the clock andwhat comes in from outside (a second launch, the browser, the automation API) run in everydiff --git a/ROADMAP.md b/ROADMAP.mdindex 2c827c95..25fa3e2d 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -13,6 +13,8 @@ Everything below ships together, in one release, as version 0.3.0.### Done+- ✅ A window closed with its title bar's × keeps its contents until it goes, instead of turning+ black for a moment (seconds on Linux) ([#207](https://github.com/anefzaoui/misterdownloadmanager/issues/207))- ✅ A freeze while MDM handles a command, or minimized, opens the crash report window and writesits freeze report again ([#202](https://github.com/anefzaoui/misterdownloadmanager/issues/202))- ✅ Where a download's server is: its country's flag and name and its round trip (near, medium ordiff --git a/crates/app/src/dialogs.rs b/crates/app/src/dialogs.rsindex c1aa340d..f7d8449d 100644--- a/crates/app/src/dialogs.rs+++ b/crates/app/src/dialogs.rs@@ -207,10 +207,9 @@ fn dialog_window<T>(}crate::crash::window(id);let out = ctx.show_viewport_immediate(ViewportId::from_hash_of(id), builder, |ui, _| {- if ui.ctx().input(|i| i.viewport().close_requested()) {- return Outcome::Closed;- }- egui::CentralPanel::no_frame()+ // Painted in the pass that closes it too (see close_requested).+ let close = close_requested(ui);+ let out = egui::CentralPanel::no_frame().frame(egui::Frame::new().fill(bg)).show(ui, |ui| {let origin = ui.max_rect().min;@@ -218,7 +217,8 @@ fn dialog_window<T>(let _surface = winui::Surface::enter(origin.x, origin.x + client[0]);body(ui, origin)})- .inner+ .inner;+ if close { Outcome::Closed } else { out }});// Give the window IDM's modal-dialog frame (3 px borders, 26 px caption) once it exists,// and again at a new size (a dialog that grows: the frame is sized from the client).@@ -265,6 +265,15 @@ fn dialog_window<T>(out}+/// Whether the window manager asked this window to close (its title bar's ×, Alt+F4, a+/// `WM_DELETE_WINDOW`). The window must still be painted in that pass, and the request honoured+/// after it: egui clears a dialog's window to transparent black before each pass, so a pass that+/// paints nothing leaves a black window on screen until the window is destroyed (#207: one to+/// several seconds on Linux).+pub(crate) fn close_requested(ui: &Ui) -> bool {+ ui.ctx().input(|i| i.viewport().close_requested())+}+/// Bring dialog `id` to the front with the keyboard focus once it shows (a window that opens by/// itself with news, such as a new version found at start, as apps announce theirs). Call every/// frame while it should; true once done. Off-screen test runs never take the focus.@@ -2680,4 +2689,81 @@ mod tests {rx.recv_timeout(std::time::Duration::from_secs(20)).expect("Add URL hung");}++ /// #207: a dialog closed by the window manager (its title bar's ×) is painted in the pass+ /// that closes it. The dialog's window is rendered as eframe renders it: its own pass, after+ /// the window was cleared to transparent black. A pass that painted nothing left the window+ /// black on screen until it was destroyed (seconds, on Linux).+ #[test]+ fn a_dialog_closed_by_the_window_manager_is_painted_in_its_last_pass() {+ use std::cell::{Cell, RefCell};+ use std::rc::Rc;++ let close = Rc::new(Cell::new(false));+ // How many shapes each pass of the dialog's window painted.+ let painted = Rc::new(RefCell::new(Vec::new()));+ {+ let (close, painted) = (close.clone(), painted.clone());+ egui::Context::set_immediate_viewport_renderer(move |ctx, viewport| {+ let mut info = egui::ViewportInfo::default();+ if close.get() {+ info.events.push(egui::ViewportEvent::Close);+ }+ let input = egui::RawInput {+ viewport_id: viewport.ids.this,+ viewports: std::iter::once((viewport.ids.this, info)).collect(),+ screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(300.0, 200.0))),+ ..Default::default()+ };+ let mut ui_cb = viewport.viewport_ui_cb;+ let mut out = ctx.run_ui(input, |ui| ui_cb(ui));+ out.textures_delta.clear();+ painted.borrow_mut().push(out.shapes.len());+ });+ }+ // A test-only title, kept out of the catalog (extract.py reads literal titles).+ let title = String::from("test window");+ let title = title.as_str();+ let ctx = egui::Context::default();+ ctx.set_embed_viewports(false);+ let pass = |closing: bool| {+ close.set(closing);+ let mut outcome = None;+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {+ outcome = Some(window(+ ui.ctx(),+ "test-207",+ title,+ [300.0, 200.0],+ false,+ egui::Color32::LIGHT_GRAY,+ |ui, origin| {+ ui.painter().text(+ origin + vec2(10.0, 10.0),+ egui::Align2::LEFT_TOP,+ "Mister Download Manager",+ egui::FontId::proportional(12.0),+ egui::Color32::BLACK,+ );+ Outcome::<()>::Open+ },+ ));+ });+ out.textures_delta.clear();+ outcome.unwrap()+ };+ assert!(matches!(pass(false), Outcome::Open));+ assert!(matches!(pass(true), Outcome::Closed));+ let painted = painted.borrow();+ assert_eq!(+ painted.len(),+ 2,+ "the dialog's window rendered once per pass"+ );+ assert!(painted[0] > 0, "the open dialog painted nothing");+ assert_eq!(+ painted[1], painted[0],+ "the pass that closes the dialog paints it as the one before"+ );+ }}diff --git a/crates/app/src/progress.rs b/crates/app/src/progress.rsindex 75641e70..b5ec6bfa 100644--- a/crates/app/src/progress.rs+++ b/crates/app/src/progress.rs@@ -291,10 +291,12 @@ impl Progress {ViewportId::from_hash_of(("progress", self.id)),builder,|ui, _| {- if ui.ctx().input(|i| i.viewport().close_requested()) {- return Action::Close;- }- if minimize_hides && ui.ctx().input(|i| i.viewport().minimized == Some(true)) {+ // Painted in the pass that closes it too (see dialogs::close_requested).+ let close = crate::dialogs::close_requested(ui);+ if !close+ && minimize_hides+ && ui.ctx().input(|i| i.viewport().minimized == Some(true))+ {return Action::Hide;}let action = egui::CentralPanel::no_frame()@@ -325,6 +327,9 @@ impl Progress {}}).inner;+ if close {+ return Action::Close;+ }// Escape hides the window (the download goes on), as the × does.if matches!(action, Action::None) && winui::escape_pressed(ui) {Action::Close