Web: check the autosave deadline from the font-poll tick (#1775)

A ten-minute time::every on wasm piles up long setTimeouts in the shared
wasmtimer driver until it stops waking every timer, which silenced the
automation channel and drop-open about 8 s after load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-14 12:21:11 +03:00
1 parent 814dd2e3d6
commit d915489a67
2 files changed
+36 -5

No files matched your search

+32 -3
View File
@@ -850,15 +850,23 @@ impl OpenCADStudio {
// Web: fetch every script queued by startup language selection or // Web: fetch every script queued by startup language selection or
// drawing text discovery. Each script has one shared store entry. // drawing text discovery. Each script has one shared store entry.
Message::PollWebFonts => { Message::PollWebFonts => {
#[cfg(target_arch = "wasm32")]
let autosave = if web_autosave_due(self.savetime_min) {
self.on_autosave()
} else {
Task::none()
};
#[cfg(not(target_arch = "wasm32"))]
let autosave = Task::none();
let pending = crate::scene::text::web_font::take_pending(); let pending = crate::scene::text::web_font::take_pending();
if pending.is_empty() { if pending.is_empty() {
return Task::none(); return autosave;
} }
Task::batch(pending.into_iter().map(|script| { Task::batch(std::iter::once(autosave).chain(pending.into_iter().map(|script| {
Task::perform(crate::scene::text::web_font::fetch(script), move |res| { Task::perform(crate::scene::text::web_font::fetch(script), move |res| {
Message::WebFontLoaded(script, res) Message::WebFontLoaded(script, res)
}) })
})) })))
} }
// Web: a per-script font arrived. The same bytes feed drawing text, // Web: a per-script font arrived. The same bytes feed drawing text,
@@ -12347,3 +12355,24 @@ fn set_preview_bit(current: u8, bit: u8, enabled: bool) -> u8 {
current & !bit current & !bit
} }
} }
/// Web autosave deadline (SAVETIME minutes), polled from a short tick: the
/// first call arms it, a later one past it re-arms it and answers true.
#[cfg(target_arch = "wasm32")]
fn web_autosave_due(savetime_min: i32) -> bool {
use std::cell::Cell;
thread_local!(static DUE_MS: Cell<f64> = const { Cell::new(0.0) });
let now = js_sys::Date::now();
let period = savetime_min.max(0) as f64 * 60_000.0;
DUE_MS.with(|due| {
if period == 0.0 || due.get() == 0.0 {
due.set(if period == 0.0 { 0.0 } else { now + period });
return false;
}
let fire = now >= due.get();
if fire {
due.set(now + period);
}
fire
})
}
+4 -2
View File
@@ -2512,8 +2512,10 @@ impl OpenCADStudio {
let web_fonts = Subscription::none(); let web_fonts = Subscription::none();
// Periodic autosave (SAVETIME): a `.sv$` recovery copy beside the file // Periodic autosave (SAVETIME): a `.sv$` recovery copy beside the file
// on native, an OPFS snapshot on web. SAVETIME is the interval in // on native, an OPFS snapshot on web. SAVETIME is the interval in
// minutes; 0 disables it. // minutes; 0 disables it. The web build checks the deadline from the
let autosave = if self.savetime_min > 0 { // `PollWebFonts` tick instead: a long `time::every` there stalls every
// other timer for its whole period (#1775).
let autosave = if self.savetime_min > 0 && cfg!(not(target_arch = "wasm32")) {
iced::time::every(std::time::Duration::from_secs( iced::time::every(std::time::Duration::from_secs(
self.savetime_min as u64 * 60, self.savetime_min as u64 * 60,
)) ))