From 425417b36adc6ed4f70f68655b252ecd5dafa94c Mon Sep 17 00:00:00 2001 From: kaltenbrunnermarkus <153593707+kaltenbrunnermarkus@users.noreply.github.com> Date: Sun, 1 Nov 2026 00:17:15 +0000 Subject: [PATCH] Web app: open a large design without freezing the page, with progress and Cancel (#10198) (#10211) * Engine: open a design a feature at a time (#10198) OpenSteps splits doc.open of a design into steps for a caller that must keep working meanwhile (the web app, which has one thread): start reads the file, each step evaluates the next feature by moving a copy's history marker one feature on (so every result before it is reused), and finish puts the design in the session's place with doc.open's reply. The next feature's imported STEP text is offered first, so a caller can read it in parts. Session::opened and opened_at are split into small helpers so both paths build the session the same way; doc.open is unchanged. Co-Authored-By: Claude Opus 5.5 * Web app: open a design a few features a frame, with progress and Cancel (#10198) On the web, a design to open is now a staged file load like a STEP file (#1376): its features are evaluated for about 30 ms a frame through OpenSteps, a feature's imported STEP file is read a solid per frame first and held so the feature finds it read, the progress card counts the design's features, Cancel works between steps, and the meshes are made a few per frame afterwards. The desktop app keeps its worker thread. Co-Authored-By: Claude Opus 5.5 * Web app: design links and the files window open designs with progress and Cancel (#10198) Design links (?open=URL, as embedded viewers use), the files window and designs opened from the computer went through the one-shot open_path, which froze the page on a large design. They now use the staged open; a design link becomes an unsaved copy under the link's name once the open's reply arrives (SolveApp::open_path_answered). Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- apps/solidcraft-web/src/linked.rs | 35 ++++++++++++++++++++++++------- apps/solidcraft-web/src/main.rs | 7 ++++--- crates/ui-egui/src/lib.rs | 12 +++++++++++ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/apps/solidcraft-web/src/linked.rs b/apps/solidcraft-web/src/linked.rs index 24e073d5d..f75d99446 100644 --- a/apps/solidcraft-web/src/linked.rs +++ b/apps/solidcraft-web/src/linked.rs @@ -15,6 +15,9 @@ type Reply = Result<(String, Vec), String>; pub struct Download { reply: Rc>>, pending: Option<(String, Vec)>, + /// The downloaded design being opened (a few features a frame, #10198): the answer to come, + /// the name it takes and the file it was read from. + opening: Option<(std::sync::mpsc::Receiver, String, String)>, } impl Download { @@ -33,13 +36,14 @@ impl Download { } pub fn tick(&mut self, app: &mut SolveApp, ctx: &egui::Context) { + self.opened(app); if let Some(reply) = self.reply.borrow_mut().take() { match reply { Ok(file) => self.pending = Some(file), Err(error) => app.set_status(format!("Could not open design link: {error}"), true), } } - if self.pending.is_none() || app.file_picker_busy() { + if self.pending.is_none() || self.opening.is_some() || app.file_picker_busy() { return; } if solidcraft_ui_egui::documents::any_dirty(app) { @@ -71,18 +75,33 @@ impl Download { } } let Some((name, bytes)) = self.pending.take() else { return }; - // The extension selects the design loader even when the URL has no extension. - let path = &format!("/linked/design.{}", solidcraft_engine::io::DESIGN_EXT); - vfs::insert(path, bytes); - app.open_path(path); - if app.session.path.as_deref() == Some(path.as_str()) { + // The extension selects the design loader even when the URL has no extension. Named + // after the link, as the progress card shows the file's name. + let file: String = name.chars().map(|c| if matches!(c, '/' | '\\') { '_' } else { c }).collect(); + let path = format!("/linked/{}.{}", if file.is_empty() { "design" } else { &file }, solidcraft_engine::io::DESIGN_EXT); + vfs::insert(&path, bytes); + // Opened as any design is, with its progress and Cancel; finished in `opened`. + self.opening = Some((app.open_path_answered(&path), name, path)); + self.opened(app); + } + + /// The downloaded design is in: it is an unsaved copy under the link's name. + fn opened(&mut self, app: &mut SolveApp) { + let Some((rx, _, _)) = &self.opening else { return }; + let (ok, cancelled) = match rx.try_recv() { + Ok(reply) => (reply["ok"].as_bool() == Some(true), reply["error"].as_str().is_some_and(|e| e.contains("cancelled"))), + Err(std::sync::mpsc::TryRecvError::Empty) => return, + Err(std::sync::mpsc::TryRecvError::Disconnected) => (false, false), + }; + let Some((_, name, path)) = self.opening.take() else { return }; + if ok && app.session.path.as_deref() == Some(path.as_str()) { app.session.path = None; app.session.doc_mut().name = name; app.session.mark_unsaved(); - } else { + } else if !ok && !cancelled { app.set_status("Could not open design link: the downloaded file is not a valid SolidCraft design", true); } - let _ = vfs::remove(path); + let _ = vfs::remove(&path); } } diff --git a/apps/solidcraft-web/src/main.rs b/apps/solidcraft-web/src/main.rs index 641cca8f6..ec3bd8ace 100644 --- a/apps/solidcraft-web/src/main.rs +++ b/apps/solidcraft-web/src/main.rs @@ -375,7 +375,8 @@ mod web { // Designs opened from the computer's disk (the files window): open them. let opened: Vec<_> = self.files.opened.borrow_mut().drain(..).collect(); for path in opened { - self.app.open_path(&path); + // A few features a frame, with progress and Cancel (#10198). + self.app.open_path_async(&path); self.files.panel.set(false); } // Recent designs whose file is gone are dropped from the list. @@ -416,7 +417,7 @@ mod web { path }; match intent { - Intent::Open => self.app.open_path(&path), + Intent::Open => self.app.open_path_async(&path), Intent::Insert | Intent::Theme => self.app.drop_path(&path), } self.files.panel.set(false); @@ -580,7 +581,7 @@ mod web { let path = format!("{}{name}", files::OPFS); match what { "open" => { - self.app.open_path(&path); + self.app.open_path_async(&path); self.files.panel.set(false); } "insert" => { diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 18426501b..51d3218b3 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -2345,6 +2345,18 @@ impl SolveApp { pub fn open_path_async(&mut self, path: &str) { file_load::begin(self, path, false); } + /// Open `path` as [`Self::open_path_async`] does, for a caller that has more to do once the + /// design is in (the web app's design links, #10198): the receiver gets `{"ok": true, ...}` + /// when it is, or `{"ok": false, "error"}`; it is dropped unanswered when the load is. + pub fn open_path_answered(&mut self, path: &str) -> std::sync::mpsc::Receiver { + let (tx, rx) = std::sync::mpsc::channel(); + let mut request = file_load::Request::new(path, file_load::Kind::Open); + request.reply = Some(tx); + if let Err(e) = file_load::begin_request(self, request) { + self.set_status(e, true); + } + rx + } pub fn insert_path_async(&mut self, path: &str) { file_load::begin(self, path, true); }