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
Linux: fonts looked up all at once while MDM starts, not one by one in the window (#164) (#175)
Ahmed Nefzaoui86dc92c31981
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1c67dc6c..5ce9df32 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -339,6 +339,12 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see### Fixed+- **Linux: the first window opens seconds sooner, and no longer freezes on a busy computer**+ (part of [#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164)): MDM asked+ fontconfig for its fonts one at a time (one program for each of some thirty scripts, more each+ time the language list opened) while the window waited, 2 s on an idle computer and long+ enough on a busy one for a freeze report on the very first start. It now asks once, all+ together, while the rest of MDM starts.- **A server without ranges no longer sends the file twice**([#136](https://github.com/anefzaoui/misterdownloadmanager/issues/136)): when the extraconnections' answers came late (a busy computer), the download could finish and then start overdiff --git a/ROADMAP.md b/ROADMAP.mdindex 20010f50..9542af4e 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -13,6 +13,9 @@ Everything below ships together, in one release.### Done+- ✅ Linux: MDM's first window opens seconds sooner; the system's fonts are looked up all at once+ while it starts, not one by one in the window (on a busy computer that froze it, part of+ [#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164))- ✅ Firefox's add-on offered from [addons.mozilla.org](https://addons.mozilla.org/firefox/addon/mister-download-manager/)first: **Add to Firefox** on the website, in the help, the FAQ and the README, and in MDM's**Add Mister Download Manager to your browser** window (for Zen and LibreWolf too); Chrome,diff --git a/crates/app/src/main.rs b/crates/app/src/main.rsindex 511a50a1..07be3102 100644--- a/crates/app/src/main.rs+++ b/crates/app/src/main.rs@@ -219,6 +219,9 @@ fn app() -> eframe::Result {};#[cfg(windows)]win32::mark_running();+ // This launch is MDM: its fonts are looked up while the rest starts (only the instance pays+ // for them, not a launch that hands its command over).+ theme::prepare_fonts();// What an earlier update set aside (old programs, a Mac's old app, downloaded files).update::tidy();// The command channel opens now, before the window: the browser's host that started MDMdiff --git a/crates/app/src/theme.rs b/crates/app/src/theme.rsindex a564b534..08b63ce3 100644--- a/crates/app/src/theme.rs+++ b/crates/app/src/theme.rs@@ -235,15 +235,57 @@ fn script_fonts(code: &str, all: bool) -> Vec<(String, Vec<u8>)> {}}-/// The font file fontconfig picks for `pattern`.+/// The font file fontconfig picks for `pattern` (one of [`fc_files`]'s).#[cfg(not(any(windows, target_os = "macos")))]fn fc_match(pattern: &str) -> Option<std::path::PathBuf> {- let out = std::process::Command::new("fc-match")- .args(["-f", "%{file}", pattern])- .output()- .ok()?;- let file = String::from_utf8(out.stdout).ok()?;- (out.status.success() && !file.trim().is_empty()).then(|| file.trim().into())+ fc_files().get(pattern).cloned()+}++/// Every font file the windows may need, as fontconfig picks it: the interface font+/// (`sans-serif`) and each script's (`:lang=…`). Each answer is an `fc-match` program; asked one+/// after the other on the window's thread, the thirty of them held up MDM's first frame for 2 s+/// on an idle computer and past the freeze report's 8 s on a busy one (#164). So they are asked+/// once, all together (a third of the time), and [`prepare_fonts`] starts that while the window+/// opens; the fonts only wait for what is still running. A font installed while MDM runs is+/// used from its next start.+#[cfg(not(any(windows, target_os = "macos")))]+fn fc_files() -> &'static std::collections::HashMap<String, std::path::PathBuf> {+ use std::process::{Command, Stdio};+ static FILES: std::sync::OnceLock<std::collections::HashMap<String, std::path::PathBuf>> =+ std::sync::OnceLock::new();+ FILES.get_or_init(|| {+ let running: Vec<_> = std::iter::once("sans-serif".to_owned())+ .chain(SCRIPT_LANGS.iter().map(|(_, fc)| format!(":lang={fc}")))+ .filter_map(|pattern| {+ let child = Command::new("fc-match")+ .args(["-f", "%{file}", &pattern])+ .stdin(Stdio::null())+ .stdout(Stdio::piped())+ .stderr(Stdio::null())+ .spawn()+ .ok()?;+ Some((pattern, child))+ })+ .collect();+ running+ .into_iter()+ .filter_map(|(pattern, child)| {+ let out = child.wait_with_output().ok()?;+ let file = String::from_utf8(out.stdout).ok()?;+ let file = file.trim();+ (out.status.success() && !file.is_empty()).then(|| (pattern, file.into()))+ })+ .collect()+ })+}++/// Start looking up the system's fonts while the window opens (Linux: [`fc_files`]); Windows and+/// macOS read theirs from known files, quickly, when the fonts load.+pub fn prepare_fonts() {+ #[cfg(not(any(windows, target_os = "macos")))]+ let _ = std::thread::Builder::new().name("fonts".into()).spawn(|| {+ fc_files();+ });}/// The script fonts loaded now: the interface language's, or all of them.