From e46b2e7520975af38847272ce94ff5fccdf410cb Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 19:54:56 +0700 Subject: [PATCH] Fonts are scanned again when the font watch finds fonts installed or removed, as production's look at the installed fonts did, not whenever the shared catalog's generation moves: it also moves when a document's own fonts are added or removed and when another app in the process refreshes the font list, which journaled a Refresh Font List in the middle of an edit (tests::scrub::a_scrub_inside_an_open_undo_group_joins_its_step, run beside tests that refresh the fonts) --- crates/ui-egui/src/app.rs | 2 +- crates/ui-egui/src/app/fonts.rs | 31 ++++++++++++------------------- crates/ui-egui/src/lib.rs | 5 +++-- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index c27370a49d..1bdca9f1cd 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -192,7 +192,7 @@ impl VectorcraftApp { original_editor: Default::default(), screen_pick: craft::color_ui::ui::ScreenPick::new(), font_watch: None, - fonts_seen: 0, + fonts_changed: Default::default(), font_preview_owner: None, background: Default::default(), opening: Default::default(), diff --git a/crates/ui-egui/src/app/fonts.rs b/crates/ui-egui/src/app/fonts.rs index 449beac013..f327da0b42 100644 --- a/crates/ui-egui/src/app/fonts.rs +++ b/crates/ui-egui/src/app/fonts.rs @@ -27,34 +27,27 @@ impl VectorcraftApp { pub(super) fn watch_fonts(&mut self, ctx: &egui::Context) { #[cfg(not(target_arch = "wasm32"))] { - let ctx = ctx.clone(); - let watch = vectorcraft_text::FontDb::global().catalog().watch(crate::state::FONT_INSTALL_POLL, move |_| ctx.request_repaint()); + let (ctx, changed) = (ctx.clone(), std::sync::Arc::clone(&self.fonts_changed)); + let watch = vectorcraft_text::FontDb::global().catalog().watch(crate::state::FONT_INSTALL_POLL, move |_| { + changed.store(true, std::sync::atomic::Ordering::Release); + ctx.request_repaint(); + }); self.font_watch = Some(watch); } #[cfg(target_arch = "wasm32")] let _ = ctx; } - /// Once per frame: when the catalog changed since the last look, runs `text.rescanFonts`, so - /// documents and lists take up the fonts the watch ([`Self::watch_fonts`]) found. It reads no - /// input, so a second pass of a frame changes nothing. - // PLAN: keyed on the catalog's generation, as contract row ty.S2 says, not `FontDb::generation` (the settled note): that one also moves each time layout loads an installed family, which would rescan on every font first used. + /// Once per frame: when the watch ([`Self::watch_fonts`]) found fonts installed or removed since the last look, + /// runs `text.rescanFonts`, so documents and lists take up the fonts it found. It reads no input, so a second pass + /// of a frame changes nothing. + // PLAN: contract row ty.S2 keys this on the catalog's generation; that also moves when a document's own fonts are + // added or removed and when another app in the process rescans, which production's look at the installed fonts + // never rescanned for, so it is keyed on what the watch found. pub(super) fn follow_fonts(&mut self) { - let catalog = vectorcraft_text::FontDb::global().catalog(); - // Until the first scan ends there is nothing to follow, and its end changes no document. - if !catalog.is_ready() { - return; - } - let generation = catalog.generation(); - if generation == self.fonts_seen { - return; - } - // 0: the first look after the first scan (the generation is at least 1 once it ran). - if self.fonts_seen != 0 { + if self.fonts_changed.swap(false, std::sync::atomic::Ordering::AcqRel) { // A failure shows in the status bar, as the menu item's does. let _ = self.run("text.rescanFonts", json!({})); } - // The command's own rescan moves the generation too. - self.fonts_seen = catalog.generation(); } } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 6e126e1f77..6c31d626fd 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -230,8 +230,9 @@ pub struct VectorcraftApp { pub(crate) screen_pick: craft::color_ui::ui::ScreenPick, /// The font catalog's watch for fonts installed or removed while the app runs. pub(crate) font_watch: Option, - /// The font catalog generation the documents' fonts were last scanned again for. - pub(crate) fonts_seen: u64, + /// Set by [`Self::font_watch`] when it found fonts installed or removed, until the documents' fonts are scanned + /// again for them. + pub(crate) fonts_changed: std::sync::Arc, /// The font menu whose live preview the canvas shows, while one does. pub(crate) font_preview_owner: Option, /// Saves and exports running in the background (Preferences → File Handling).