mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-02 22:49:48 -06:00
LR-BEHAV-TOAST: menu commands' toasts show
The UI's menu commands made their toasts with a fresh egui context, whose clock starts at 0, while the app checks a toast's end against its own clock: once the app had run a few seconds, every such toast (Auto Advance On, presets imported or exported, the keyword painter, …) was over before it was drawn. They use the app's context now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
967edfcd80
commit
3d75952562
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user