Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

LR-BEHAV-TOAST: menu commands' toasts show

Nathaniel Ledford3d7595256248
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 5b79548b9..73e62d383 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -266,7 +266,9 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option<Re
crate::i18n::set_language(app.ui.language);
return Some(Ok(json!(app.ui.language)));
}
- let ctx = egui::Context::default();
+ // the app's own context: a toast's time comes from its clock (a fresh context's clock is at 0,
+ // and a toast set by it was long over by the app's clock: it never showed)
+ let ctx = app.tasks.repaint.clone().unwrap_or_default();
let r: Result<Value, String> = match id {
"view.photoGrid" => {
app.ui.view = ViewMode::PhotoGrid;
diff --git a/crates/ui-egui/src/tests_panels.rs b/crates/ui-egui/src/tests_panels.rs
index 66eb360e1..592e77716 100644
--- a/crates/ui-egui/src/tests_panels.rs
+++ b/crates/ui-egui/src/tests_panels.rs
@@ -1096,3 +1096,20 @@ fn date_and_keyword_rows_show_their_photos_from_any_source() {
h.step();
assert_eq!(h.app.session.filter, lightcraft_catalog::Filter::default(), "{key}");
}
+
+/// A menu command's toast shows, however long the app has been running: commands made their
+/// toasts with a fresh context, whose clock is at 0, so by the app's clock they were already over
+/// (Auto Advance On, Imported presets, …).
+#[test]
+fn a_menu_commands_toast_shows_after_a_while() {
+ let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services { png: None, ..Default::default() });
+ let mut h = crate::headless::Headless::new(app, [1000.0, 700.0], 1.0);
+ for _ in 0..600 {
+ h.step();
+ }
+ let r = h.request("engine.execute", serde_json::json!({"command": "view.autoAdvance"}), std::time::Duration::from_secs(10));
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ assert!(h.app.ui.toast.as_ref().is_some_and(|t| t.0.starts_with("Auto Advance")), "{:?}", h.app.ui.toast);
+}