fix(start): decode recent-file thumbnails off the boot path

load_config synchronously parsed every recent DWG's embedded preview
on the main thread before the first frame, so the Start page appeared
seconds late on DWG-heavy recents. refresh_recent_thumbs now decodes
the missing previews on a background thread and delivers them via
RecentThumbsLoaded; the page opens immediately and thumbnails pop in
as they resolve. The web build (no threads, no filesystem previews)
skips the fetch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Fable 5 committed 2026-07-21 10:06:55 +03:00
1 parent b6720230c9
commit c938d56ac6
2 files changed
+48 -14

No files matched your search

+44 -11
View File
@@ -12,23 +12,56 @@ pub(super) const RECENT_MAX: usize = 100;
pub(super) const RECENT_DEFAULT: usize = 20;
impl OpenCADStudio {
/// Record a freshly opened file at the top of the recents list.
pub(super) fn push_recent(&mut self, path: PathBuf) {
/// Record a freshly opened file at the top of the recents list. Returns
/// the background task that decodes its thumbnail.
pub(super) fn push_recent(&mut self, path: PathBuf) -> iced::Task<crate::app::Message> {
self.recent_files.retain(|r| r != &path);
self.recent_files.insert(0, path);
self.recent_files.truncate(self.recent_limit);
self.refresh_recent_thumbs();
self.save_config();
self.refresh_recent_thumbs()
}
/// Decode any not-yet-cached DWG preview thumbnails for the current recents
/// (cheap preview-only reads). Cached per path; safe to call repeatedly.
/// Call when the recents list changes — never from a `view`.
pub(super) fn refresh_recent_thumbs(&mut self) {
for path in self.recent_files.clone() {
self.recent_thumbs
.entry(path.clone())
.or_insert_with(|| crate::io::thumbnail::read_handle(&path));
/// Decode any not-yet-cached DWG preview thumbnails for the current
/// recents on a background thread, delivering them via
/// [`Message::RecentThumbsLoaded`]. The synchronous version of this ran on
/// the boot path and stalled the first frame for as long as it took to
/// parse every recent DWG's preview — the Start page appeared seconds
/// late. Cached per path (a `None` result is cached too); safe to call
/// repeatedly.
pub(super) fn refresh_recent_thumbs(&mut self) -> iced::Task<crate::app::Message> {
let missing: Vec<std::path::PathBuf> = self
.recent_files
.iter()
.filter(|p| !self.recent_thumbs.contains_key(*p))
.cloned()
.collect();
if missing.is_empty() {
return iced::Task::none();
}
// The web build has no spawnable threads and no filesystem previews —
// recents there simply show without thumbnails.
#[cfg(target_arch = "wasm32")]
{
return iced::Task::none();
}
#[cfg(not(target_arch = "wasm32"))]
{
let (tx, rx) = iced::futures::channel::oneshot::channel();
std::thread::spawn(move || {
let thumbs: Vec<_> = missing
.into_iter()
.map(|p| {
let h = crate::io::thumbnail::read_handle(&p);
(p, h)
})
.collect();
let _ = tx.send(thumbs);
});
iced::Task::perform(
async move { rx.await.unwrap_or_default() },
crate::app::Message::RecentThumbsLoaded,
)
}
}
+4 -3
View File
@@ -296,7 +296,8 @@ impl OpenCADStudio {
.clamp(crate::app::recent::RECENT_MIN, crate::app::recent::RECENT_MAX);
self.recent_files.truncate(self.recent_limit);
self.recent_limit_input = self.recent_limit.to_string();
self.refresh_recent_thumbs();
// Thumbnails are decoded by a background task queued at boot
// (`refresh_recent_thumbs`) — never here on the boot path.
self.statusbar_config = cfg.statusbar;
self.ribbon.set_collapse_mode(cfg.ribbon.collapse);
self.plot_dialog = cfg.plot;
@@ -396,7 +397,7 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
caches.corrupt_dropped
));
}
self.push_recent(path.clone());
let thumbs_task = self.push_recent(path.clone());
let current_is_empty = {
let t = &self.tabs[self.active_tab];
@@ -587,7 +588,7 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
self.tabs[i].dirty = false;
self.tabs[i].history = crate::app::document::HistoryState::default();
self.refresh_selected_grips();
self.drain_pending_open()
Task::batch([thumbs_task, self.drain_pending_open()])
}
pub(super) fn on_wblock_save_result_some(&mut self, block_name: String, path: std::path::PathBuf) -> Task<Message> {