PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Preferences: Save in Background off saves in the foreground (#6207)
David Manna3cbc880e6a9
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rsindex c732daeef..0cbb7c6b9 100644--- a/crates/engine/src/prefs.rs+++ b/crates/engine/src/prefs.rs@@ -439,6 +439,8 @@ impl Default for HistoryLog {pub struct FileHandling {pub image_previews: Ask,pub lowercase_extension: bool,+ /// Saves run in the background while you keep working (on), or in the foreground under a+ /// modal progress dialog that blocks the app until the file is written (off).pub save_in_background: bool,/// Save recovery information (crash recovery autosave).pub autosave: bool,@@ -1014,7 +1016,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &["general.zoomResizesWindows","workspace.autoShowHiddenPanels","workspace.enableFloatingDocumentWindowDocking",- "fileHandling.saveInBackground","performance.cacheLevels","performance.effectCacheMb","performance.legacyCompositing",diff --git a/crates/ui-egui/src/jobs_ui.rs b/crates/ui-egui/src/jobs_ui.rsindex 29da41d48..45fa60d8a 100644--- a/crates/ui-egui/src/jobs_ui.rs+++ b/crates/ui-egui/src/jobs_ui.rs@@ -10,8 +10,12 @@//! shown after a short delay so quick jobs don't flash it. Esc cancels.//! - Files opening in the background get a document tab at once ([`OpenTab`]); its canvas area//! shows the progress, and closing the tab cancels the open.-//! - Saves encode and write on a worker ([`start_save`], #2017) under the modal progress dialog;-//! the document is locked meanwhile, and the save is recorded when the job ends.+//! - Saves encode and write on a worker ([`start_save`], #2017); the document is locked+//! meanwhile, and the save is recorded when the job ends. With Preferences › File Handling ›+//! Save in Background on (the default) you keep working while the file is written, the progress+//! in the document's tab and the status bar; off, the save runs in the foreground (#6207): the+//! modal progress dialog shows at once and no shortcut or tool input reaches the app until the+//! file is complete ([`foreground_save`]).//!//! The canvas keeps showing the pre-job state: workers never touch the session's documents.@@ -147,6 +151,9 @@ pub struct SaveJob {/// The job has ended (cancelled, say) but its worker may still be running: kept until it/// returns, so quitting and another save to the same file wait for it.pub ended: bool,+ /// Started with Save in Background off: the app waits for it under the modal progress dialog+ /// (see [`foreground_save`]).+ pub foreground: bool,}/// The shell's job bookkeeping.@@ -301,7 +308,9 @@ pub fn start_save(Ok(Some((path, warnings)))}Started::Job(job) => {- app.jobs.saves.push(SaveJob { job, doc, revision, path, copy, automation, state, ended: false });+ // Preferences › File Handling › Save in Background, read when the save starts.+ let foreground = !app.session.prefs().file_handling.save_in_background;+ app.jobs.saves.push(SaveJob { job, doc, revision, path, copy, automation, state, ended: false, foreground });// Control and MCP requests wait on it, as for other jobs.app.jobs.last_started = Some(job);// The status bar's progress readout names the save; clear any old message.@@ -394,9 +403,20 @@ pub fn keep_polling(app: &PhotocraftApp, ctx: &egui::Context) -> bool {true}-/// The job the user is looking at: the open tab in view, the active document's job, or (for-/// the status bar) the newest running job.+/// The save the app is waiting on, while it runs: one started with Preferences › File Handling ›+/// Save in Background off (#6207). Like Photoshop's foreground save it blocks the app: the modal+/// progress dialog shows at once ([`dialog`]) and no shortcut or tool reaches the documents+/// until the file is written; anything after it (a close prompt, quitting) waits for it.+pub fn foreground_save(app: &PhotocraftApp) -> Option<JobInfo> {+ app.jobs.saves.iter().filter(|s| s.foreground && !s.ended).find_map(|s| app.session.job(s.job))+}++/// The job the user is looking at: a foreground save, the open tab in view, the active+/// document's job, or (for the status bar) the newest running job.pub fn job_in_view(app: &PhotocraftApp) -> Option<JobInfo> {+ if let Some(j) = foreground_save(app) {+ return Some(j);+ }if let Some(j) = app.jobs.focus.and_then(|j| app.session.job(j)) {return Some(j);}@@ -697,12 +717,20 @@ pub fn status_progress(app: &mut PhotocraftApp, ui: &mut egui::Ui) {/// The modal progress window for a job locking the active document (Photoshop shows one for/// long filters): title, status, bar, percentage and elapsed time, Cancel. Appears after-/// [`DIALOG_DELAY_MS`]; Esc cancels (see [`tick`]).+/// [`DIALOG_DELAY_MS`]; Esc cancels (see [`tick`]). A save shows it only when it runs in the+/// foreground (Save in Background off), and then at once, so nothing can be clicked meanwhile; a+/// background save shows its progress in the tab and the status bar instead.pub fn dialog(app: &mut PhotocraftApp, ctx: &egui::Context) {- let Some(j) = app.session.active_job() else { return };- if j.elapsed_ms < DIALOG_DELAY_MS {- return;- }+ let j = match foreground_save(app) {+ Some(j) => j,+ None => {+ let Some(j) = app.session.active_job() else { return };+ if j.elapsed_ms < DIALOG_DELAY_MS || app.jobs.saves.iter().any(|s| s.job == j.id) {+ return;+ }+ j+ }+ };let t = Tokens::get(ctx);let mut cancel_it = false;// Photoshop doesn't dim the window behind its progress dialog either.diff --git a/crates/ui-egui/src/jobs_ui_tests.rs b/crates/ui-egui/src/jobs_ui_tests.rsindex f2b7d0fbc..1661ba6cb 100644--- a/crates/ui-egui/src/jobs_ui_tests.rs+++ b/crates/ui-egui/src/jobs_ui_tests.rs@@ -430,11 +430,15 @@ fn saves_run_in_the_background_and_are_recorded_when_they_end() {let st = h.state().session.active().unwrap();assert!(st.is_dirty() && st.path.is_none());assert!(h.state_mut().run("layer.new.layer", json!({})).is_err(), "the saving document is locked");- // The progress dialog names the save and shows its stage; the status bar reads "Saving 0%"- // until the encoder reports progress (#3389).- assert_eq!(h.query_all_by_label("Saving big.psd").count(), 1);- h.get_by_label("Encoding");+ // Save in Background is on by default: no modal dialog, so the rest of the app stays usable+ // (#6207); the status bar reads "Saving 0%" until the encoder reports progress (#3389).+ assert!(h.query_by_label("Esc to cancel").is_none() && h.query_by_label("Encoding").is_none(), "no progress dialog");h.get_by_label("Saving 0%");+ assert!(crate::jobs_ui::foreground_save(h.state()).is_none());+ h.state_mut().ui.tool = crate::state::Tool::Move;+ h.key_press(egui::Key::B);+ h.run_steps(2);+ assert_eq!(h.state().ui.tool, crate::state::Tool::Brush, "shortcuts still work while it saves");gates.encode.store(true, Ordering::Relaxed);step_until(&mut h, |a| !a.saving());@@ -448,6 +452,86 @@ fn saves_run_in_the_background_and_are_recorded_when_they_end() {assert!(h.state_mut().run("layer.new.layer", json!({})).is_ok(), "unlocked again");}+/// Save in Background off (#6207): the same worker writes the file, but the app waits for it+/// like Photoshop's foreground save. The progress dialog shows at once, shortcuts don't reach the+/// app, and a close asked for meanwhile happens only once the file is complete.+#[test]+fn save_in_background_off_blocks_the_app_until_the_file_is_written() {+ let mut h = app_harness();+ h.state_mut().run("prefs.set", json!({"path": "fileHandling.saveInBackground", "value": false})).unwrap();+ let gates = Gates { write: Arc::new(AtomicBool::new(true)), ..Gates::default() };+ h.state_mut().services.save_file = Some(gates.save(None));+ h.state_mut().ui.tool = crate::state::Tool::Move;+ let r = h.state_mut().save_as(Some("/tmp/photocraft-test/fg.psd".into())).unwrap();+ assert_eq!(r["pending"], true, "the same background job does the work");+ h.run_steps(1);+ // The dialog is up from the first frame (no delay), titled with the save, then its stage.+ h.get_by_label("Saving fg.psd");+ h.get_by_label("Esc to cancel");+ let t = Instant::now();+ while h.query_by_label("Encoding").is_none() && t.elapsed() < Duration::from_secs(30) {+ h.step();+ }+ h.get_by_label("Encoding");+ assert!(crate::jobs_ui::foreground_save(h.state()).is_some());+ h.key_press(egui::Key::B);+ h.run_steps(2);+ assert_eq!(h.state().ui.tool, crate::state::Tool::Move, "no shortcut reaches the app while it saves");+ assert!(h.state_mut().run("layer.new.layer", json!({})).is_err(), "the saving document is locked");+ // Quitting now waits for the file.+ let st = h.state_mut().session.active_mut().unwrap();+ st.saved_revision = st.revision;+ assert!(press_window_close(h.state_mut()), "the close waits for the save");+ assert!(h.state().jobs.close_after_saves);++ gates.encode.store(true, Ordering::Relaxed);+ let t = Instant::now();+ while h.state().jobs.close_after_saves && t.elapsed() < Duration::from_secs(30) {+ h.step();+ if h.state().jobs.close_after_saves {+ assert!(h.query_by_label("Esc to cancel").is_some(), "the dialog stays up until the save ends");+ }+ }+ assert_eq!(gates.written(), ["/tmp/photocraft-test/fg.psd"], "the file is complete before the close goes on");+ assert!(!h.state().jobs.close_after_saves, "then the held close is repeated");+ h.run_steps(2);+ assert!(h.query_by_label("Esc to cancel").is_none(), "the dialog is gone");+ let st = h.state().session.active().unwrap();+ assert_eq!(st.path.as_deref(), Some("/tmp/photocraft-test/fg.psd"));+ assert!(!st.is_dirty());+ h.key_press(egui::Key::B);+ h.run_steps(2);+ assert_eq!(h.state().ui.tool, crate::state::Tool::Brush, "shortcuts work again");+}++/// A failing foreground save reports its error, closes its dialog and leaves the document+/// unsaved, as a background one does; Esc still cancels one that is encoding.+#[test]+fn a_failed_or_cancelled_foreground_save_leaves_the_document_unsaved() {+ let mut h = app_harness();+ h.state_mut().run("prefs.set", json!({"path": "fileHandling.saveInBackground", "value": false})).unwrap();+ let gates = Gates::open();+ h.state_mut().services.save_file = Some(gates.save(Some("disk full")));+ h.state_mut().save_as(Some("/tmp/photocraft-test/f.psd".into())).unwrap();+ step_until(&mut h, |a| !a.saving());+ let st = h.state().session.active().unwrap();+ assert!(st.is_dirty() && st.path.is_none());+ assert!(noticed(h.state(), "disk full"), "the failure is reported");+ assert!(h.query_by_label("Esc to cancel").is_none(), "the dialog is gone");++ gates.encode.store(false, Ordering::Relaxed);+ h.state_mut().services.save_file = Some(gates.save(None));+ h.state_mut().save_as(Some("/tmp/photocraft-test/g.psd".into())).unwrap();+ h.run_steps(2);+ h.key_press(egui::Key::Escape);+ step_until(&mut h, |a| !a.saving());+ assert!(gates.written().is_empty(), "nothing written");+ let st = h.state().session.active().unwrap();+ assert!(st.is_dirty() && st.path.is_none());+ assert_eq!(h.state().ui.status, "Cancelled Saving g.psd");+ assert!(crate::jobs_ui::foreground_save(h.state()).is_none());+}+#[test]fn a_failed_save_or_one_cancelled_while_encoding_leaves_the_document_unsaved() {let mut h = app_harness();diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rsindex e8645a151..abb0a7bf7 100644--- a/crates/ui-egui/src/shortcuts.rs+++ b/crates/ui-egui/src/shortcuts.rs@@ -341,6 +341,11 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {if app.camera_raw.is_some() {return;}+ // A foreground save (Save in Background off, #6207) blocks the app until the file is written;+ // only Esc reaches it, to cancel while it still encodes (see `jobs_ui::tick`).+ if crate::jobs_ui::foreground_save(app).is_some() {+ return;+ }// An open menu owns the keyboard (arrows, ↩, Esc), like a native menu; so does the menu bar// once Alt or F10 put the keyboard on it (#4988), and an open dropdown list, whose letters// pick an option rather than a tool (#1481).diff --git a/docs/gaps.md b/docs/gaps.mdindex faf0884c8..324dbf12b 100644--- a/docs/gaps.md+++ b/docs/gaps.md@@ -1,6 +1,6 @@# Where PhotoCraft falls short of Photoshop-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (G1: smart filter masks show on PSD open, Photoshop-oracle floor 188/258; G10: DPX read and write, #1049, Cineon read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; G1: pass-through clipping base with an adjustment renders isolated, psd-tools oracle floor 240/309; G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-15 · **Change:** minor (G9: Preferences › File Handling › Save in Background takes effect, #6207, 25 of 166 preferences do nothing; G1: smart filter masks show on PSD open, Photoshop-oracle floor 188/258; G10: DPX read and write, #1049, Cineon read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; G1: pass-through clipping base with an adjustment renders isolated, psd-tools oracle floor 240/309; G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026Every known shortfall against Photoshop 2026 (27.11.0), one entry each, ranked by user impacton the way to beta. This is the work list agents pick from: take the highest-ranked entry that@@ -197,7 +197,8 @@ what an agent can't finish alone.### G9. Panels, preferences and workspace- **Progress (2026-10-12):** toolbar tool shortcuts can be reassigned, removed and reset (#4086),with saved bindings, matching toolbar hints and regression coverage (`ui-egui/src/tool_shortcuts.rs`).-- **Missing:** 27 of 156 preferences do nothing (scorecard prefs audit); panel groups can't+- **Missing:** 25 of 166 preferences do nothing (scorecard prefs audit, 2026-10-15: Save in+ Background now takes effect, #6207); panel groups can'tfloat or tear off into OS windows (UI-217-5, #1828, #1213, #2305); Color panel lacks wheel andslider modes (UI-217-17, #2569); more themes (UI-217-11, #2661); layer clipboard(UI-217-23, #2670); tool-specific context menus beyond brushes, selections and Pen@@ -270,6 +271,7 @@ what an agent can't finish alone.| Date | Change | Summary ||---|---|---|+| 2026-10-15 | minor | G9: Save in Background off saves in the foreground under a modal progress dialog (#6207); preferences that do nothing 26 → 25 of 166 || 2026-10-14 | minor | G1: a PSD smart object's filter mask shows when the file opens (Photoshop stores the filtered pixels unmasked); export stores them that way too; Photoshop-oracle floor 185 → 188 of 258 || 2026-10-13 | minor | G14: D90 image area measured (4288 × 2848 at (10, 10)); gap remains open || 2026-10-14 | minor | Corpus floors raised to the measured results of the CMYK, Lab, 32-bit, Levels, Threshold, Posterize, feather and pass-through fixes landed together: Photoshop-authored 165 → 185 of 258, io 146 → 148 of 170, psd-tools 242 → 249 of 309 |diff --git a/docs/scorecard.md b/docs/scorecard.mdindex 1e0576ba0..a92e9494e 100644--- a/docs/scorecard.md+++ b/docs/scorecard.md@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) || [File compatibility](#file-compatibility) | 7 | 14 | 6 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 188/256, round trip ≥ 258/256 || [Tools](#tools) | 33 | 11 | 0 | |-| [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 26 of 166 (target 0) |+| [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 25 of 166 (target 0) || [Type](#type) | 4 | 3 | 2 | || [Automation](#automation) | 5 | 2 | 4 | 631 of 631 menu items live (100.0%) || [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 29 of 29 crates; panic_hunt present |@@ -177,9 +177,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t## Workspace and UI-**Settings that do nothing: 26 of 166** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.+**Settings that do nothing: 25 of 166** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.-Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `file_handling.save_in_background`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.+Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.| Id | Target | Status | Issue | Note ||---|---|---|---|---|