From 250ba3e76a67eadd0fdcbe9616012bb0b11b710b Mon Sep 17 00:00:00 2001 From: yoriswind Date: Mon, 30 Nov 2026 17:43:53 -0800 Subject: [PATCH] Apply completed jobs while showing progress --- crates/ui-egui/src/export_progress.rs | 3 +-- crates/ui-egui/src/lib.rs | 7 ++++++- crates/ui-egui/src/opening.rs | 2 +- crates/ui-egui/src/opening/tests.rs | 18 ++++++++++++++++++ crates/ui-egui/src/placing.rs | 2 +- crates/ui-egui/src/placing/tests.rs | 5 ++++- crates/ui-egui/src/plugin_runs.rs | 2 +- crates/ui-egui/src/retype_runs.rs | 2 +- crates/ui-egui/src/trace_runs.rs | 2 +- 9 files changed, 34 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/export_progress.rs b/crates/ui-egui/src/export_progress.rs index 3bad229898..1f1245000d 100644 --- a/crates/ui-egui/src/export_progress.rs +++ b/crates/ui-egui/src/export_progress.rs @@ -13,7 +13,6 @@ use std::time::Duration; use craft::ui::dialog::{JobAnswer, JobProgress}; -use craft::ui::runtime::overlay::OpenFilter; use serde_json::json; use crate::VectorcraftApp; @@ -69,7 +68,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) { return; } // Progress is modal for input, but the window must not block itself on its next pass. - if app.dialog_open(OpenFilter::Asks) { + if app.asking_dialog_open() { return; } let Shown { title, step, fraction, counts, queued, cancel, hide, .. } = shown; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 6af6aa3b22..8a931c60b3 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -378,8 +378,13 @@ impl VectorcraftApp { self.dialog_open(OpenFilter::Modal) } + /// Whether a question or popup is open. Applying a job's result can close its progress window. + pub(crate) fn asking_dialog_open(&self) -> bool { + self.dialog_open(OpenFilter::Asks) + } + /// Whether a layer matching the filter, a popup or a pending app modal is open. - pub(crate) fn dialog_open(&self, filter: OpenFilter) -> bool { + fn dialog_open(&self, filter: OpenFilter) -> bool { // A modeless layer with a focus scope (the canvas's task bar) takes keys too, and blocks nothing. let popup = |ctx: &egui::Context| overlay::top(ctx).and_then(|id| overlay::entry(ctx, id)).is_some_and(|e| e.rank == overlay::Rank::Popup); self.ui_ctx.as_ref().is_some_and(|ctx| overlay::any_open(ctx, filter) || popup(ctx)) diff --git a/crates/ui-egui/src/opening.rs b/crates/ui-egui/src/opening.rs index 5e72952fe2..541b033cff 100644 --- a/crates/ui-egui/src/opening.rs +++ b/crates/ui-egui/src/opening.rs @@ -148,7 +148,7 @@ fn track(app: &mut VectorcraftApp, path: &str, done: Receiver bool { - if app.any_dialog_open() || crate::dialogs::missing_fonts::waiting(app) { + if app.asking_dialog_open() || crate::dialogs::missing_fonts::waiting(app) { return false; } let s = &app.session; diff --git a/crates/ui-egui/src/opening/tests.rs b/crates/ui-egui/src/opening/tests.rs index c1eaa83f8e..0dd4c4c3b7 100644 --- a/crates/ui-egui/src/opening/tests.rs +++ b/crates/ui-egui/src/opening/tests.rs @@ -573,6 +573,24 @@ fn a_file_that_takes_a_while_to_open_shows_a_progress_window() { assert_eq!(app.session.documents().len(), before + 2); } +#[test] +fn a_file_ready_while_progress_is_visible_opens_without_hiding_progress() { + let mut app = VectorcraftApp::new(Session::new(), Services::default()); + app.now_override = Some(0.0); + let ctx = crate::testing::ui_context(); + app.adopt_context(&ctx); + start(&mut app, "/art/Big.vectorcraft", bytes("Big")); + age(&mut app); + progress(&mut app, &ctx); + assert!(progress(&mut app, &ctx).contains("Opening Big.vectorcraft")); + assert!(app.any_dialog_open()); + + open_ready(&mut app); + assert!(app.opening.pending.is_empty()); + assert_eq!(app.session.doc().unwrap().path.as_deref(), Some("/art/Big.vectorcraft")); + assert_eq!(progress(&mut app, &ctx), "", "completion closes progress"); +} + /// #5930: the progress window's Cancel (`file.cancelOpen`): the file doesn't open, even once it /// has been read, and the status bar no longer says it is opening. #[test] diff --git a/crates/ui-egui/src/placing.rs b/crates/ui-egui/src/placing.rs index 972e907fea..9d1cc5be02 100644 --- a/crates/ui-egui/src/placing.rs +++ b/crates/ui-egui/src/placing.rs @@ -445,7 +445,7 @@ fn spawn_labeled( /// the file is placed unless the tool has a preview open (the Flare tool after its center drag). pub fn poll(app: &mut VectorcraftApp) { settle_swatch_paste(app); - while !app.any_dialog_open() + while !app.asking_dialog_open() && !app.session.in_interaction() && !(app.session.tool_busy() && app.session.pointer_held()) && let Some(p) = app.placing.pending.first() diff --git a/crates/ui-egui/src/placing/tests.rs b/crates/ui-egui/src/placing/tests.rs index fb75d86663..dc6a19e0fc 100644 --- a/crates/ui-egui/src/placing/tests.rs +++ b/crates/ui-egui/src/placing/tests.rs @@ -1980,6 +1980,7 @@ fn a_file_that_takes_a_while_to_place_shows_a_progress_window() { app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); let ctx = crate::testing::ui_context(); + app.adopt_context(&ctx); assert_eq!(progress(&mut app, &ctx), "", "nothing placing"); let slow_path = saved("progress", "slow.png", &picture(Png, 100, 100)); @@ -2002,10 +2003,12 @@ fn a_file_that_takes_a_while_to_place_shows_a_progress_window() { start(&mut app, &json!({"path": next_path, "at": [200, 150]}), false).unwrap(); let texts = progress(&mut app, &ctx); assert!(texts.contains("Placing slow.png…") && texts.contains("waiting"), "{texts}"); + assert!(app.any_dialog_open()); - // Release and finish + // Releasing the read applies both files without dismissing the progress window first. drop(go); placed(&mut app); + assert_eq!(progress(&mut app, &ctx), "", "completion closes progress"); } /// #5930: cancelling a place aborts the operation, drops the parsed asset, leaves the document diff --git a/crates/ui-egui/src/plugin_runs.rs b/crates/ui-egui/src/plugin_runs.rs index 067302ddcb..a5be54af01 100644 --- a/crates/ui-egui/src/plugin_runs.rs +++ b/crates/ui-egui/src/plugin_runs.rs @@ -458,7 +458,7 @@ pub fn poll(app: &mut VectorcraftApp) { poll_checks(app); let mut i = 0; while let Some(r) = app.plugin_runs.running.get(i) { - let dialog = app.any_dialog_open() || app.session.script_running(); + let dialog = app.asking_dialog_open() || app.session.script_running(); let ended = match &r.backend { Backend::Thread(_) if dialog => None, Backend::Worker(..) if dialog => watch_worker(app, i), diff --git a/crates/ui-egui/src/retype_runs.rs b/crates/ui-egui/src/retype_runs.rs index 81f774d5d3..c51c5a6a8f 100644 --- a/crates/ui-egui/src/retype_runs.rs +++ b/crates/ui-egui/src/retype_runs.rs @@ -130,7 +130,7 @@ fn stop(app: &mut VectorcraftApp) { /// Runs the command of the search that is done (each frame). Not while a dialog is open, nor while /// an interaction is open or a tool drags with the pointer button held, as [`crate::trace_runs::poll`]. pub fn poll(app: &mut VectorcraftApp) { - if app.any_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) { + if app.asking_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) { return; } let Some(r) = &app.retype_runs.running else { return }; diff --git a/crates/ui-egui/src/trace_runs.rs b/crates/ui-egui/src/trace_runs.rs index 341c0c4113..c554b21add 100644 --- a/crates/ui-egui/src/trace_runs.rs +++ b/crates/ui-egui/src/trace_runs.rs @@ -140,7 +140,7 @@ pub fn start(app: &mut VectorcraftApp, command: &str, p: Value, from_panel: bool /// dialog is open (its OK acts on the active document, which a trace's result changes), nor while /// an interaction is open or a tool drags with the pointer button held, as [`crate::placing::poll`]. pub fn poll(app: &mut VectorcraftApp) { - if app.any_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) { + if app.asking_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) { return; } let mut i = 0;