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:
parent
b6720230c9
commit
c938d56ac6
2 changed files with 48 additions and 14 deletions
|
|
@ -12,23 +12,56 @@ pub(super) const RECENT_MAX: usize = 100;
|
||||||
pub(super) const RECENT_DEFAULT: usize = 20;
|
pub(super) const RECENT_DEFAULT: usize = 20;
|
||||||
|
|
||||||
impl OpenCADStudio {
|
impl OpenCADStudio {
|
||||||
/// Record a freshly opened file at the top of the recents list.
|
/// Record a freshly opened file at the top of the recents list. Returns
|
||||||
pub(super) fn push_recent(&mut self, path: PathBuf) {
|
/// 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.retain(|r| r != &path);
|
||||||
self.recent_files.insert(0, path);
|
self.recent_files.insert(0, path);
|
||||||
self.recent_files.truncate(self.recent_limit);
|
self.recent_files.truncate(self.recent_limit);
|
||||||
self.refresh_recent_thumbs();
|
|
||||||
self.save_config();
|
self.save_config();
|
||||||
|
self.refresh_recent_thumbs()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode any not-yet-cached DWG preview thumbnails for the current recents
|
/// Decode any not-yet-cached DWG preview thumbnails for the current
|
||||||
/// (cheap preview-only reads). Cached per path; safe to call repeatedly.
|
/// recents on a background thread, delivering them via
|
||||||
/// Call when the recents list changes — never from a `view`.
|
/// [`Message::RecentThumbsLoaded`]. The synchronous version of this ran on
|
||||||
pub(super) fn refresh_recent_thumbs(&mut self) {
|
/// the boot path and stalled the first frame for as long as it took to
|
||||||
for path in self.recent_files.clone() {
|
/// parse every recent DWG's preview — the Start page appeared seconds
|
||||||
self.recent_thumbs
|
/// late. Cached per path (a `None` result is cached too); safe to call
|
||||||
.entry(path.clone())
|
/// repeatedly.
|
||||||
.or_insert_with(|| crate::io::thumbnail::read_handle(&path));
|
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,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -296,7 +296,8 @@ impl OpenCADStudio {
|
||||||
.clamp(crate::app::recent::RECENT_MIN, crate::app::recent::RECENT_MAX);
|
.clamp(crate::app::recent::RECENT_MIN, crate::app::recent::RECENT_MAX);
|
||||||
self.recent_files.truncate(self.recent_limit);
|
self.recent_files.truncate(self.recent_limit);
|
||||||
self.recent_limit_input = self.recent_limit.to_string();
|
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.statusbar_config = cfg.statusbar;
|
||||||
self.ribbon.set_collapse_mode(cfg.ribbon.collapse);
|
self.ribbon.set_collapse_mode(cfg.ribbon.collapse);
|
||||||
self.plot_dialog = cfg.plot;
|
self.plot_dialog = cfg.plot;
|
||||||
|
|
@ -396,7 +397,7 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
|
||||||
caches.corrupt_dropped
|
caches.corrupt_dropped
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
self.push_recent(path.clone());
|
let thumbs_task = self.push_recent(path.clone());
|
||||||
|
|
||||||
let current_is_empty = {
|
let current_is_empty = {
|
||||||
let t = &self.tabs[self.active_tab];
|
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].dirty = false;
|
||||||
self.tabs[i].history = crate::app::document::HistoryState::default();
|
self.tabs[i].history = crate::app::document::HistoryState::default();
|
||||||
self.refresh_selected_grips();
|
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> {
|
pub(super) fn on_wblock_save_result_some(&mut self, block_name: String, path: std::path::PathBuf) -> Task<Message> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue