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
Every mark drawn in every language; browser and video-helper windows mirror and fit (#185, #170) (#189)
Ahmed Nefzaoui09310e6b41e5
diff --git a/ROADMAP.md b/ROADMAP.mdindex 7d3d32f6..ff5681d7 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -13,6 +13,11 @@ Everything below ships together, in one release, as version 0.3.0.### Done+- ✅ Every mark in the windows is drawn in every language (the browser window's ✔ Connected+ was an empty box, → on Linux), and the browser and video-helper windows put their logo at the+ start side in Arabic and Persian and fit a long German headline and subline+ ([#185](https://github.com/anefzaoui/misterdownloadmanager/issues/185),+ [#170](https://github.com/anefzaoui/misterdownloadmanager/issues/170))- ✅ A Linux test machine for every change, scripted: an Ubuntu 24.04 desktop that builds eachbranch and drives MDM, Firefox and Chrome there (part of[#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164))@@ -192,9 +197,6 @@ Everything below ships together, in one release, as version 0.3.0.MDM; no address is sent anywhere ([#140](https://github.com/anefzaoui/misterdownloadmanager/issues/140))- 🔄 Torrents: download in order, to watch a video while it downloads; the other torrents rarestfirst ([#39](https://github.com/anefzaoui/misterdownloadmanager/issues/39))-- 🔄 MDM's browser window: the check mark before **Connected** shows in every language (an empty- box in Arabic and on Linux), the German subtitle fits, the Arabic layout is mirrored- ([#185](https://github.com/anefzaoui/misterdownloadmanager/issues/185), [#170](https://github.com/anefzaoui/misterdownloadmanager/issues/170))- 🔄 Linux supported like Windows, no longer experimental: every change is now checked on Ubuntu(GNOME) as well as Windows, then on KDE, Cinnamon and Xfce ([#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164))- 🔄 Before the release: every screenshot taken again on Windows and Linux (smaller files, WebP),diff --git a/crates/app/src/crashui.rs b/crates/app/src/crashui.rsindex e011c3fc..836b4cd8 100644--- a/crates/app/src/crashui.rs+++ b/crates/app/src/crashui.rs@@ -359,7 +359,7 @@ impl ReportWindow {.load_texture("crash-icon", img, egui::TextureOptions::LINEAR)});egui::Image::new((icon.id(), egui::vec2(32.0, 32.0)))- .paint_at(ui, winui::rect(r(o, 16.0, 16.0, 32.0, 32.0)));+ .paint_at(ui, r(o, 16.0, 16.0, 32.0, 32.0));winui::text_font(&p,winui::tahoma_bold(),diff --git a/crates/app/src/extension.rs b/crates/app/src/extension.rsindex 3999ac7c..ca1bc46d 100644--- a/crates/app/src/extension.rs+++ b/crates/app/src/extension.rs@@ -9,7 +9,7 @@use std::path::PathBuf;use std::time::Duration;-use egui::{FontFamily, FontId, Pos2, Ui};+use egui::{Pos2, Ui};use crate::dialogs::{Outcome, window};use crate::winui::{self, ButtonKind, r};@@ -97,13 +97,15 @@ impl Extension {}ctx.request_repaint_after(Duration::from_secs(1));let h = BANNER + 16.0 + self.browsers.len() as f32 * ROW + 104.0;+ // A long translation's subline makes the banner taller (winui::banner).+ let extra = crate::dialogs::grow_extra(ctx, "extension-banner");let mut answer = None;window(ctx,"extension",// i18n: title of the window that offers the browser extension"Add Mister Download Manager to your browser",- [W, h],+ [W, h + extra],false,winui::BG(),|ui, o| {@@ -122,37 +124,20 @@ impl Extension {let p = ui.painter().clone();let (ink, muted) = (winui::TEXT(), winui::MUTED());// The banner: the logo, what the extension does, in one line, and how.- p.rect_filled(winui::rect(r(o, 0.0, 0.0, W, BANNER)), 0.0, winui::FIELD());- winui::fill_l(- &p,- o.x,- o.y + BANNER,- o.x + W - 1.0,- o.y + BANNER,- winui::FIELD_EDGE(),- );- egui::Image::new(egui::include_image!("../assets/icons/app/mdm-48.png"))- .paint_at(ui, winui::rect(r(o, 18.0, 18.0, 48.0, 48.0)));- winui::text_font(+ let extra = winui::banner(+ ui,&p,- FontId::new(16.0, FontFamily::Name("tahoma-bold".into())),- o.x + 80.0,- o.y + 36.0,+ o,+ W,+ "extension-banner",// i18n: the headline of the window that offers the browser extensioncrate::i18n::t("Catch downloads from your browser"),- ink,- );- winui::paragraph(- &p,- o.x + 80.0,- o.y + 57.0,crate::i18n::t("Add the free extension: files you download in your browser come here, and videos get a Download button.",),- muted,- o.x + W - 18.0,- 14.0,);+ // Everything below it moves down with a taller banner.+ let o = o + egui::vec2(0.0, extra);// One row per browser: its name, and the button that opens the extension's page in it:// Firefox's on addons.mozilla.org, the Chrome Web Store's for the others (the tutorialdiff --git a/crates/app/src/helpers.rs b/crates/app/src/helpers.rsindex 72cc5c43..a30e2ee0 100644--- a/crates/app/src/helpers.rs+++ b/crates/app/src/helpers.rs@@ -6,7 +6,7 @@use std::sync::Arc;use std::sync::Mutex;-use egui::{FontFamily, FontId, Pos2, Ui};+use egui::{Pos2, Ui};use crate::dialogs::{Outcome, window};use crate::icons::Icon;@@ -122,13 +122,18 @@ impl Helpers {ctx.request_repaint_after(std::time::Duration::from_millis(150));}let mut answer = None;+ // A long translation's subline makes the banner taller (winui::banner).+ let extra = crate::dialogs::grow_extra(ctx, "helpers-banner");window(ctx,"helpers",// i18n: title of the first start's window that offers yt-dlp and ffmpeg"Get ready for video downloads",// Taller once Yes is pressed: the progress under the last section.- [520.0, if self.job.is_some() { 418.0 } else { 382.0 }],+ [+ 520.0,+ if self.job.is_some() { 418.0 } else { 382.0 } + extra,+ ],false,winui::BG(),|ui, o| {@@ -158,38 +163,20 @@ impl Helpers {let (ink, muted) = (winui::TEXT(), winui::MUTED());let w = 520.0;// The banner: MDM's own logo, what this is for, in one line, and why now.- p.rect_filled(winui::rect(r(o, 0.0, 0.0, w, 84.0)), 0.0, winui::FIELD());- winui::fill_l(- &p,- o.x,- o.y + 84.0,- o.x + w - 1.0,- o.y + 84.0,- winui::FIELD_EDGE(),- );- egui::Image::new(egui::include_image!("../assets/icons/app/mdm-48.png"))- .paint_at(ui, winui::rect(r(o, 18.0, 18.0, 48.0, 48.0)));- let title = FontId::new(16.0, FontFamily::Name("tahoma-bold".into()));- winui::text_font(+ let extra = winui::banner(+ ui,&p,- title,- o.x + 80.0,- o.y + 36.0,+ o,+ w,+ "helpers-banner",// i18n: the headline of the first start's helpers windowcrate::i18n::t("Download videos from YouTube and 1,000+ sites"),- ink,- );- winui::paragraph(- &p,- o.x + 80.0,- o.y + 57.0,crate::i18n::t("Two free helpers make it work. Get them now, and saving a video is one click away when you find one.",),- muted,- o.x + w - 18.0,- 14.0,);+ // Everything below it moves down with a taller banner.+ let o = o + egui::vec2(0.0, extra);let ffmpeg_here = !cfg!(windows)&& self@@ -236,7 +223,7 @@ impl Helpers {for (k, (icon, name, what)) in rows.iter().enumerate() {let y = 100.0 + k as f32 * 72.0;icon.image(true)- .paint_at(ui, winui::rect(r(o, 22.0, y + 2.0, 32.0, 32.0)));+ .paint_at(ui, r(o, 22.0, y + 2.0, 32.0, 32.0));winui::text_font(&p,winui::tahoma_bold(),@@ -323,11 +310,7 @@ impl Helpers {};drop(st);let bar_w = 320.0;- winui::meter(- &p,- winui::rect(r(o, (w - bar_w) / 2.0, 312.0, bar_w, 8.0)),- fraction,- );+ winui::meter(&p, r(o, (w - bar_w) / 2.0, 312.0, bar_w, 8.0), fraction);// Centred on screen (the same place in both directions); cut to the window.let room = w - 40.0;let shown = winui::ellipsize(&p, &winui::tahoma(), &line, room);diff --git a/crates/app/src/theme.rs b/crates/app/src/theme.rsindex 08b63ce3..92a82024 100644--- a/crates/app/src/theme.rs+++ b/crates/app/src/theme.rs@@ -179,6 +179,32 @@ const SCRIPT_LANGS: &[(&str, &str)] = &[("ml", "ml"),];+/// Marks that neither the interface font nor the script fonts have (✔ ✖ ↩ ⇧ ⌘ ⌥ ⌦, and → on+/// Linux: #185): the system's symbol fonts, last in every family's chain, in every language,+/// each one that is there. macOS keeps ✔ and ✖ in Zapf Dingbats, not in Apple Symbols.+#[cfg(windows)]+const SYMBOL_FONTS: &[&str] = &["seguisym.ttf"];+#[cfg(target_os = "macos")]+const SYMBOL_FONTS: &[&str] = &["Apple Symbols.ttf", "ZapfDingbats.ttf"];+/// Linux: the font fontconfig picks for those marks (glyph_tests lists every one the windows+/// draw; a new one goes here too).+#[cfg(not(any(windows, target_os = "macos")))]+const SYMBOL_PATTERN: &str = ":charset=2024 2192 21a9 21e7 2318 2325 2326 2714 2716";++/// The symbol fonts' bytes, in fallback order ([`SYMBOL_FONTS`], [`SYMBOL_PATTERN`]).+fn symbol_fonts() -> Vec<Vec<u8>> {+ #[cfg(any(windows, target_os = "macos"))]+ return SYMBOL_FONTS+ .iter()+ .filter_map(|f| std::fs::read(font_dir().join(f)).ok())+ .collect();+ #[cfg(not(any(windows, target_os = "macos")))]+ return fc_match(SYMBOL_PATTERN)+ .and_then(|f| std::fs::read(f).ok())+ .into_iter()+ .collect();+}+/// The folder the font tables name files in.#[cfg(any(windows, target_os = "macos"))]fn font_dir() -> std::path::PathBuf {@@ -254,7 +280,9 @@ fn fc_files() -> &'static std::collections::HashMap<String, std::path::PathBuf>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())+ let running: Vec<_> = ["sans-serif", SYMBOL_PATTERN]+ .into_iter()+ .map(str::to_owned).chain(SCRIPT_LANGS.iter().map(|(_, fc)| format!(":lang={fc}"))).filter_map(|pattern| {let child = Command::new("fc-match")@@ -378,6 +406,11 @@ fn fonts(ctx: &egui::Context, code: &str, all: bool) {defs.font_data.insert(key.clone(), on_baseline(bytes));fallbacks.push(key);}+ for (k, bytes) in symbol_fonts().into_iter().enumerate() {+ let key = format!("symbols-{k}");+ defs.font_data.insert(key.clone(), on_baseline(bytes));+ fallbacks.push(key);+ }for list in defs.families.values_mut() {for f in &fallbacks {// Segoe UI already leads the two built-in families (as itself, not a fallback).@@ -488,3 +521,171 @@ mod mode_tests {}}}++/// Every mark a window draws (punctuation, arrows, ✔, quotation marks…: what isn't a letter or a+/// digit) has a glyph in every language's font chain, so none comes out as an empty box (#185:+/// "✔ Connected" in the browser offer window; "→" on Linux).+#[cfg(test)]+mod glyph_tests {+ use std::collections::{BTreeMap, BTreeSet};+ use std::path::Path;+ use unicode_segmentation::UnicodeSegmentation;++ const ROOT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../..");++ /// Drawn as nothing on purpose: bidi controls and isolates, joiners, the soft hyphen, the+ /// BOM (craft-i18n's isolates around data, the translations' own marks).+ fn invisible(c: char) -> bool {+ matches!(c, '\u{00ad}' | '\u{200b}'..='\u{200f}' | '\u{202a}'..='\u{202e}'+ | '\u{2060}'..='\u{2069}' | '\u{feff}' | '\u{fe00}'..='\u{fe0f}')+ }++ /// The marks in `text`: each grapheme's first character that is neither a letter, a digit,+ /// a space nor invisible (a grapheme's other characters are its accents and joiners).+ fn marks(text: &str, out: &mut BTreeSet<char>) {+ for g in text.graphemes(true) {+ if let Some(c) = g.chars().next()+ && !c.is_alphanumeric()+ && !c.is_whitespace()+ && !c.is_control()+ && !invisible(c)+ {+ out.insert(c);+ }+ }+ }++ /// A catalog's texts: the translations (and the English sources, which a missing row shows).+ fn catalog(code: &str) -> String {+ let file = Path::new(ROOT).join("i18n").join(format!("{code}.tsv"));+ let text = std::fs::read_to_string(&file).unwrap();+ text.lines()+ .filter(|l| !l.starts_with('#') && !l.starts_with('@'))+ .flat_map(|l| l.split('\t').skip(1))+ .collect::<Vec<_>>()+ .join("\n")+ }++ /// The marks the code draws itself, beside the catalogs' ("\u{2714} {}", "→"): every+ /// string literal in the app's sources, escapes read.+ fn literals() -> BTreeSet<char> {+ let mut out = BTreeSet::new();+ let dir = Path::new(ROOT).join("crates/app/src");+ for entry in std::fs::read_dir(dir).unwrap() {+ let path = entry.unwrap().path();+ if path.extension().is_none_or(|e| e != "rs") {+ continue;+ }+ let src = std::fs::read_to_string(&path).unwrap();+ // The tests' own data (other scripts, emoji in file names) is not drawn.+ let src = src.split("#[cfg(test)]").next().unwrap_or_default();+ for lit in src.split('"').skip(1).step_by(2) {+ let mut s = String::new();+ let mut rest = lit;+ while let Some(at) = rest.find("\\u{") {+ s.push_str(&rest[..at]);+ let end = rest[at..].find('}').map_or(rest.len(), |e| at + e);+ if let Some(c) = u32::from_str_radix(&rest[at + 3..end], 16)+ .ok()+ .and_then(char::from_u32)+ {+ s.push(c);+ }+ rest = &rest[(end + 1).min(rest.len())..];+ }+ s.push_str(rest);+ // Only what isn't plain ASCII: every font has that.+ let mut found = BTreeSet::new();+ marks(&s, &mut found);+ out.extend(found.into_iter().filter(|c| !c.is_ascii()));+ }+ }+ out+ }++ fn languages() -> Vec<String> {+ let file = Path::new(ROOT).join("i18n/languages.tsv");+ std::fs::read_to_string(file)+ .unwrap()+ .lines()+ .filter(|l| !l.starts_with('#') && !l.trim().is_empty())+ .filter_map(|l| l.split('\t').next().map(str::to_owned))+ .collect()+ }++ #[test]+ fn every_language_draws_its_marks() {+ let code_marks = literals();+ let families = [+ egui::FontFamily::Name("tahoma".into()),+ egui::FontFamily::Name("tahoma-bold".into()),+ egui::FontFamily::Proportional,+ ];+ let mut missing: BTreeMap<String, BTreeSet<char>> = BTreeMap::new();+ let mut skipped = Vec::new();+ for code in languages() {+ let text = catalog(&code);+ let mut needed = code_marks.clone();+ marks(&text, &mut needed);+ let ctx = egui::Context::default();+ super::fonts(&ctx, &code, false);+ let mut out = ctx.run_ui(Default::default(), |_| {});+ out.textures_delta.clear();+ // A computer without the language's script font draws none of it (a CI image without+ // CJK fonts): nothing to check there.+ let letters: Vec<char> = text+ .chars()+ .filter(|c| c.is_alphabetic() && !c.is_ascii())+ .take(200)+ .collect();+ let has_script = ctx.fonts_mut(|f| {+ let id = egui::FontId::new(11.0, families[0].clone());+ letters.is_empty()+ || letters.iter().filter(|c| f.has_glyph(&id, **c)).count() * 10+ >= letters.len() * 9+ });+ if !has_script {+ skipped.push(code);+ continue;+ }+ for family in &families {+ let id = egui::FontId::new(11.0, family.clone());+ let lacks: Vec<char> = ctx.fonts_mut(|f| {+ needed+ .iter()+ .copied()+ .filter(|c| !f.has_glyph(&id, *c))+ .collect()+ });+ if !lacks.is_empty() {+ missing+ .entry(format!("{code} ({family:?})"))+ .or_default()+ .extend(lacks);+ }+ }+ }+ if !skipped.is_empty() {+ eprintln!(+ "no font for these languages' script on this computer, not checked: {skipped:?}"+ );+ }+ let report: Vec<String> = missing+ .iter()+ .map(|(k, v)| {+ format!(+ "{k}: {}",+ v.iter()+ .map(|c| format!("{c} U+{:04X}", *c as u32))+ .collect::<Vec<_>>()+ .join(", ")+ )+ })+ .collect();+ assert!(+ report.is_empty(),+ "marks without a glyph:\n{}",+ report.join("\n")+ );+ }+}diff --git a/crates/app/src/winui.rs b/crates/app/src/winui.rsindex ca447bc7..38d0f124 100644--- a/crates/app/src/winui.rs+++ b/crates/app/src/winui.rs@@ -215,6 +215,52 @@ pub fn galley(p: &Painter, font: FontId, s: &str, color: Color32) -> std::sync::p.layout_job(job)}+/// The banner atop a first-start window (the browser extension's offer, the video helpers):+/// MDM's logo at the start side, a bold headline, and a muted subline that wraps. 84 px tall, and+/// taller by what a long translation's extra lines need: that extra is returned, for the window+/// to add to its height and to move what is below the banner down by (it is known from the frame+/// before: [`crate::dialogs::grow_extra`] under `key`).+#[allow(clippy::too_many_arguments)]+pub fn banner(+ ui: &Ui,+ p: &Painter,+ o: Pos2,+ w: f32,+ key: &str,+ headline: &str,+ subline: &str,+) -> f32 {+ const PLANNED: f32 = 84.0;+ let extra = crate::dialogs::grow_extra(ui.ctx(), key);+ let h = PLANNED + extra;+ // `r` gives the rect where it is on screen (mirrored in RTL): the logo at the start side.+ p.rect_filled(r(o, 0.0, 0.0, w, h), 0.0, FIELD());+ fill_l(p, o.x, o.y + h, o.x + w - 1.0, o.y + h, FIELD_EDGE());+ egui::Image::new(egui::include_image!("../assets/icons/app/mdm-48.png"))+ .paint_at(ui, r(o, 18.0, 18.0, 48.0, 48.0));+ // The headline on one line: cut with "..." at the far edge (a long translation), whole on+ // hover.+ let bold = FontId::new(16.0, FontFamily::Name("tahoma-bold".into()));+ let shown = ellipsize(p, &bold, headline, w - 18.0 - 80.0);+ let drawn = text_font(p, bold, o.x + 80.0, o.y + 36.0, &shown, TEXT());+ if shown != headline {+ full_on_hover(ui, drawn, (key, "headline"), headline);+ }+ let lines = paragraph(+ p,+ o.x + 80.0,+ o.y + 57.0,+ subline,+ MUTED(),+ o.x + w - 18.0,+ 14.0,+ );+ // As planned, two lines: the second one's baseline at 71, then 13 px of descent and margin.+ let need = 57.0 + 14.0 * (lines.max(2) as f32 - 1.0) + 13.0;+ crate::dialogs::grow_px(ui.ctx(), key, need - PLANNED);+ extra+}+/// Draw `s` with its pen (its start) at English `x` and its baseline (last cap row) at/// `baseline`. Returns the text's advance rect on screen.pub fn text(p: &Painter, x: f32, baseline: f32, s: &str, color: Color32) -> Rect {@@ -4783,6 +4829,29 @@ pub mod caption {mod tests {use super::*;+ /// `r` already gives the screen rect (mirrored in RTL); `rect` around it mirrors it back,+ /// so the thing stays at its English place in Arabic (#170: the browser offer window's logo+ /// over its subline). No window does that.+ #[test]+ fn no_rect_is_mirrored_twice() {+ let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src");+ let twice = ["rect(r(", "rect(winui::r("];+ let mut found = Vec::new();+ for entry in std::fs::read_dir(dir).unwrap() {+ let path = entry.unwrap().path();+ let Ok(src) = std::fs::read_to_string(&path) else {+ continue;+ };+ for (n, line) in src.lines().enumerate() {+ let code = line.split("//").next().unwrap_or_default();+ if twice.iter().any(|t| code.contains(t)) && !code.contains("\"rect(") {+ found.push(format!("{}:{}", path.display(), n + 1));+ }+ }+ }+ assert!(found.is_empty(), "rect(r(...)) mirrors twice: {found:?}");+ }+/// `f` with a painter whose Tahoma is the interface font (as on macOS and Linux).fn with_painter(f: impl FnOnce(&Painter)) {let ctx = egui::Context::default();