From 99c7e172b08f1c8f929763aeb50d6cce6e6bbdd9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 09:12:14 -0800 Subject: [PATCH] Import: show PhotoCraft composition notes as a notice, not an error The notes about a PhotoCraft composition that was already added now go to the window as one non-error notice. With several compositions the notice leads with the first note and a count of the rest, and the finished import's toast repeats the notes. Both command results keep the warnings as before. --- crates/engine/src/cmd/file.rs | 16 ++++++-- crates/engine/src/tests/import_photocraft.rs | 43 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index f1f542135..72a2510a6 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -145,10 +145,17 @@ fn import_cmd(s: &mut Session, p: &Value) -> Result { let p = p.clone(); let immediate_errors = pending.errors.clone(); // Compositions made during preparation stay when the job is canceled, so their notes are - // shown now and returned in both results. + // shown now and returned in both results. The window keeps one notice at a time and shows + // its first line, so they go in one notice led by a summary, and the finished job's toast + // repeats them. let immediate_warnings = std::mem::take(&mut pending.warnings); - for w in &immediate_warnings { - s.events.push(crate::Event::Toast { message: w.clone(), error: true }); + let notes = match immediate_warnings.as_slice() { + [] => String::new(), + [one] => one.clone(), + [first, rest @ ..] => format!("{first} (and {} more)\n{}", rest.len(), immediate_warnings.join("\n")), + }; + if !notes.is_empty() { + s.events.push(crate::Event::Toast { message: notes.clone(), error: false }); } let job_warnings = immediate_warnings.clone(); let mut result = s.spawn_task("import", label, false, move |ctl| { @@ -175,6 +182,9 @@ fn import_cmd(s: &mut Session, p: &Value) -> Result { [one] => toast = format!("{toast}. {one}"), [first, rest @ ..] => toast = format!("{toast}. {first} (and {} more)\n{}", rest.len(), errors.join("\n")), } + if !notes.is_empty() { + toast = if errors.is_empty() { format!("{toast}. {notes}") } else { format!("{toast}\n{notes}") }; + } r["toast"] = json!(toast); Ok(r) }); diff --git a/crates/engine/src/tests/import_photocraft.rs b/crates/engine/src/tests/import_photocraft.rs index 4359b4b98..b135774c5 100644 --- a/crates/engine/src/tests/import_photocraft.rs +++ b/crates/engine/src/tests/import_photocraft.rs @@ -134,11 +134,54 @@ fn photocraft_composition_notes_arrive_before_a_background_footage_job() { assert!(r["errors"].as_array().unwrap().is_empty(), "{r}"); let notes = |r: &Value| r["warnings"].as_array().unwrap().iter().any(|w| w.as_str().is_some_and(|w| w.contains("Some masks, effects and profiles"))); assert!(notes(&r), "the composition already exists, so a canceled job must not hide its notes: {r}"); + let toast = s.drain_events().into_iter().find_map(|e| match e { + crate::Event::Toast { message, error } if message.contains("Some masks, effects and profiles") => Some(error), + _ => None, + }); + assert_eq!(toast, Some(false), "the composition was imported, so its notes are shown as a notice, not an error"); s.execute("jobs.wait", json!({})).unwrap(); + let done = s.drain_events().into_iter().find_map(|e| match e { + crate::Event::Toast { message, error } if message.starts_with("Imported") => Some((message, error)), + _ => None, + }); + let (done, error) = done.expect("the finished job shows its own toast"); + assert!(!error, "{done}"); + let shown = done.lines().next().unwrap_or_default(); + assert!( + shown.contains("Some masks, effects and profiles"), + "the job's toast replaces the notice in the window, so its first line repeats the notes: {done}" + ); std::fs::remove_file(layered).unwrap(); std::fs::remove_file(still).unwrap(); } +#[test] +fn photocraft_composition_notes_from_several_files_share_one_notice() { + let first = fixture("background-first.pcraft", json!([layer("Bottom", true, 1.0, "Normal", json!({"kind":"raster","surface":surface("ff0000ff")}))])); + let second = fixture("background-second.pcraft", json!([layer("Bottom", true, 1.0, "Normal", json!({"kind":"raster","surface":surface("00ff00ff")}))])); + let mut png = std::io::Cursor::new(Vec::new()); + image::DynamicImage::ImageRgba8(image::RgbaImage::from_pixel(2, 2, image::Rgba([1, 2, 3, 255]))).write_to(&mut png, image::ImageFormat::Png).unwrap(); + let still = fixture_bytes("background-third.png", png.into_inner()); + let mut s = Session { importer: Some(std::sync::Arc::new(Import)), ..Default::default() }; + let r = s.execute("file.import", json!({"paths":[first, second, still],"importAs":"composition","background":true})).unwrap(); + assert_eq!(r["warnings"].as_array().unwrap().len(), 2, "{r}"); + let notices: Vec = s + .drain_events() + .into_iter() + .filter_map(|e| match e { + crate::Event::Toast { message, error: false } => Some(message), + _ => None, + }) + .collect(); + let [notice] = notices.as_slice() else { panic!("one notice for both compositions: {notices:?}") }; + assert!(notice.lines().next().unwrap_or_default().ends_with("(and 1 more)"), "the shown line says another note is on hover: {notice}"); + assert_eq!(notice.lines().count(), 3, "{notice}"); + s.execute("jobs.wait", json!({})).unwrap(); + for path in [first, second, still] { + std::fs::remove_file(path).unwrap(); + } +} + #[test] fn photocraft_optional_canvas_metadata_does_not_block_probed_footage() { struct Metadata(bool);