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
macOS: the menu bar icon is made from the app icon's picture (#529) (#553)
Ahmed Nefzaoui265493bd46d0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2a4c44b4..f2d4db73 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see- macOS: file names in Persian, Arabic, Urdu, Hebrew or Armenian show their letters in the download list and windows instead of boxes, whatever the interface language: these scripts now get the font for them that comes with macOS (Arial Unicode), the first time one is needed ([#533](https://github.com/anefzaoui/misterdownloadmanager/issues/533)).- A download's progress is saved from its first seconds again: since 0.5.2, when the disk was slow to write the resume state as the download started (no data had arrived yet), the first save of its progress waited nine times as long, up to a minute, so a short download cut off by a crash or a power cut in that time started over from the beginning (part of [#518](https://github.com/anefzaoui/misterdownloadmanager/issues/518)).- macOS: **Download File Info** opens in front of the browser that asked for it ([#484](https://github.com/anefzaoui/misterdownloadmanager/issues/484)).+- macOS: MDM's icon shows in the menu bar, so closing the window keeps MDM running there instead of quitting; the icon was never made, for want of a picture ([#529](https://github.com/anefzaoui/misterdownloadmanager/issues/529)).- The browser's **video button** over a hover-to-play preview (YouTube's thumbnails) no longer vanishes as the pointer goes to it: it stays where it was while the pointer is on it, a click downloads that video, and it fades once the pointer leaves ([#503](https://github.com/anefzaoui/misterdownloadmanager/issues/503)).- **Enter new address to download**: an address with a login in **Options → Sites Logins** shows that login under **Use authorization** (ticked, the user name and the password), the one the download uses; it was used but the box stayed empty. A login typed there still goes first ([#511](https://github.com/anefzaoui/misterdownloadmanager/issues/511)).- The window no longer waits for the disk to write MDM's log or to save the RSS feeds: while Windows held every write on the disk to make a snapshot of it (a restore point or a backup), the window could stop answering until the writes were let go. Both are now written beside the window, as the download list already was (part of [#513](https://github.com/anefzaoui/misterdownloadmanager/issues/513)).diff --git a/ROADMAP.md b/ROADMAP.mdindex 9c5f5025..def3f40c 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -528,6 +528,9 @@ These ship in a later version, when they're ready.([#533](https://github.com/anefzaoui/misterdownloadmanager/issues/533)): fix in review, toconfirm on a Mac- 🔄 macOS: Download File Info opening behind the browser that asked for it\n ([#484](https://github.com/anefzaoui/misterdownloadmanager/issues/484)): fix in review+- 🔄 macOS: no icon in the menu bar, so closing the window quit MDM+ ([#529](https://github.com/anefzaoui/misterdownloadmanager/issues/529)): fix in review, still to+ confirm on a Mac- 🔄 The browser tests: the video button's focus case ran after the one that turns the buttonoff for the test site, and timed out in a full run ([#480](https://github.com/anefzaoui/misterdownloadmanager/issues/480)): fix in review- 🔄 The video button vanishing over a hover-to-play preview (YouTube's thumbnails) before itdiff --git a/crates/app/src/app.rs b/crates/app/src/app.rsindex 63df73f5..d28eca64 100644--- a/crates/app/src/app.rs+++ b/crates/app/src/app.rs@@ -3023,13 +3023,7 @@ impl App {let wanted =!crate::offscreen() || std::env::var_os("MDM_TEST_TRAY").is_some_and(|v| v == "1");if self.tray.is_none() && self.tray_limiter.is_none() && wanted {- let icon = crate::app_icon();- self.tray = crate::tray::Tray::new(- ctx,- icon.rgba.clone(),- icon.width,- self.settings.speed_limit_on,- );+ self.tray = crate::tray::Tray::new(ctx, self.settings.speed_limit_on);self.tray_limiter = Some(self.settings.speed_limit_on);if self.tray.is_some() {tracing::info!("tray icon shown");diff --git a/crates/app/src/crashui.rs b/crates/app/src/crashui.rsindex 291271b6..662994f9 100644--- a/crates/app/src/crashui.rs+++ b/crates/app/src/crashui.rs@@ -382,7 +382,7 @@ impl ReportWindow {// The app's icon and the heading.let icon = self.icon.get_or_insert_with(|| {- let i = crate::app_icon();+ let i = crate::app_picture();let img = egui::ColorImage::from_rgba_unmultiplied([i.width as usize, i.height as usize],&i.rgba,diff --git a/crates/app/src/main.rs b/crates/app/src/main.rsindex ab4468d8..5a2feff7 100644--- a/crates/app/src/main.rs+++ b/crates/app/src/main.rs@@ -81,12 +81,22 @@ pub const MAIN_TITLE: &str = concat!("Mister Download Manager ", env!("CARGO_PKG/// icon (AppIcon.icns, every size, tools/installer/build-macos.sh), which an icon set at run/// time would replace.pub fn app_icon() -> std::sync::Arc<egui::IconData> {+ if cfg!(target_os = "macos") {+ // eframe takes an empty icon as "none" (AppTitleIconSetter).+ static NONE: std::sync::OnceLock<std::sync::Arc<egui::IconData>> =+ std::sync::OnceLock::new();+ return NONE.get_or_init(Default::default).clone();+ }+ app_picture()+}++/// The app icon's picture, the 256 px size, on every system: what MDM draws or hands over as a+/// picture (the tray's icon, macOS's menu bar item; the crash report window's heading). Not+/// [`app_icon`], empty on macOS: an empty picture can't be made into the menu bar item, so macOS+/// had none and closing the window quit (#529).+pub fn app_picture() -> std::sync::Arc<egui::IconData> {static ICON: std::sync::OnceLock<std::sync::Arc<egui::IconData>> = std::sync::OnceLock::new();ICON.get_or_init(|| {- if cfg!(target_os = "macos") {- // eframe takes an empty icon as "none" (AppTitleIconSetter).- return std::sync::Arc::new(egui::IconData::default());- }let png = include_bytes!("../assets/icons/app/mdm-256.png");std::sync::Arc::new(eframe::icon_data::from_png_bytes(png).unwrap_or_default())})diff --git a/crates/app/src/tray.rs b/crates/app/src/tray.rsindex d94e90c5..1f8e3832 100644--- a/crates/app/src/tray.rs+++ b/crates/app/src/tray.rs@@ -104,8 +104,8 @@ impl Tray {shown}- /// The icon and its menu; events wake `ctx`. None if the shell refuses the icon.- pub fn new(ctx: &egui::Context, rgba: Vec<u8>, size: u32, limiter: bool) -> Option<Tray> {+ /// The icon and its menu; events wake `ctx`. None if the shell refuses the icon (logged).+ pub fn new(ctx: &egui::Context, limiter: bool) -> Option<Tray> {let menu = Menu::new();let mut items = Vec::new();let mut labels = Vec::new();@@ -159,14 +159,26 @@ impl Tray {items.push((limiter_on.id().clone(), TrayCmd::LimiterOn));items.push((limiter_off.id().clone(), TrayCmd::LimiterOff));- let icon = tray_icon::Icon::from_rgba(rgba, size, size).ok()?;- let tray = TrayIconBuilder::new()+ let icon = match picture() {+ Ok(icon) => icon,+ Err(e) => {+ tracing::warn!("tray icon: no picture: {e}");+ return None;+ }+ };+ let tray = match TrayIconBuilder::new().with_menu(Box::new(menu)).with_menu_on_left_click(false).with_tooltip(crate::MAIN_TITLE).with_icon(icon).build()- .ok()?;+ {+ Ok(tray) => tray,+ Err(e) => {+ tracing::warn!("tray icon: not made: {e}");+ return None;+ }+ };let (tx, rx) = channel();let wake = |tx: &Sender<TrayCmd>, ctx: &egui::Context| (tx.clone(), ctx.clone());@@ -301,6 +313,18 @@ fn short(name: &str) -> String {s.replace('&', "&&")}+/// The icon's picture: the app icon's ([`crate::app_picture`]), square. Never an empty one:+/// tray-icon takes a 0×0 picture, and macOS then fails to make the menu bar item of it (it+/// encodes the picture as a PNG, which can't be 0 wide), so before #529 macOS had no menu bar+/// icon and closing the window quit.+fn picture() -> Result<tray_icon::Icon, String> {+ let p = crate::app_picture();+ if p.width == 0 || p.width != p.height {+ return Err(format!("{}×{} px", p.width, p.height));+ }+ tray_icon::Icon::from_rgba(p.rgba.clone(), p.width, p.height).map_err(|e| e.to_string())+}+#[cfg(test)]mod tests {use super::*;@@ -312,4 +336,21 @@ mod tests {assert_eq!(s.chars().count(), MENU_NAME_MAX + 1);assert!(s.ends_with('…'));}++ /// #529: the tray's picture is a real one on every system, macOS's menu bar included (where+ /// the window icon, `app_icon`, is empty on purpose).+ #[test]+ fn the_tray_picture_is_never_empty() {+ let p = crate::app_picture();+ assert_eq!((p.width, p.height), (256, 256));+ assert_eq!(p.rgba.len(), 256 * 256 * 4);+ assert!(p.rgba.chunks(4).any(|px| px[3] > 0), "a blank picture");+ assert!(picture().is_ok());+ #[cfg(target_os = "macos")]+ assert_eq!(+ crate::app_icon().width,+ 0,+ "the Dock keeps the bundle's icon"+ );+ }}