Open: draw the Home picture after the design opens (#3053) (#3140)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bherbruck
2026-10-19 15:44:06 -04:00
committed by GitHub
parent f3505f0db6
commit b00d45cc7b
3 changed files with 20 additions and 18 deletions
+12 -13
View File
@@ -81,7 +81,8 @@ impl Request {
struct Made {
session: Session,
result: Value,
image: Option<egui::ColorImage>,
/// Draw its Home picture once it is open (off the UI thread: a large design takes a while).
thumbnail: bool,
}
type Job = Result<Made, String>;
struct Running {
@@ -508,8 +509,7 @@ fn step_staged(running: &mut Running) {
}
let (Some(session), Some(result)) = (staged.session.take(), staged.ran.take()) else { return };
let thumbnail = staged.command == "doc.open" && staged.triangles <= STAGED_THUMBNAIL_TRIANGLES;
let image = if thumbnail { crate::home::remember(&session) } else { None };
send(staged, Ok(Made { session, result, image }));
send(staged, Ok(Made { session, result, thumbnail }));
return;
}
let Some(reading) = staged.reading.as_mut() else {
@@ -727,7 +727,7 @@ fn compute(
if command == "file.export_view_dxf" {
// A successful export has already published its complete file. A Cancel arriving
// after that commit must not turn a completed save into a misleading cancellation.
return Ok(Made { session, result, image: None });
return Ok(Made { session, result, thumbnail: false });
}
if progress.is_cancelled() {
return cancelled();
@@ -746,16 +746,13 @@ fn compute(
let tessellation_ms = mesh_began.elapsed().as_secs_f64() * 1000.0;
phase.store(2, Ordering::Relaxed);
let view_ms = view_began.elapsed().as_secs_f64() * 1000.0;
let thumbnail_began = std::time::Instant::now();
let image = if thumbnail { crate::home::remember(&session) } else { None };
if profile {
eprintln!(
"SolidCraft open phases: geometry_ms={geometry_ms:.3} placement_ms={placement_ms:.3} tessellation_ms={tessellation_ms:.3} display_warmup_ms={view_ms:.3} thumbnail_ms={:.3} total_ms={:.3}",
thumbnail_began.elapsed().as_secs_f64() * 1000.0,
"SolidCraft open phases: geometry_ms={geometry_ms:.3} placement_ms={placement_ms:.3} tessellation_ms={tessellation_ms:.3} display_warmup_ms={view_ms:.3} total_ms={:.3}",
began.elapsed().as_secs_f64() * 1000.0
);
}
Ok(Made { session, result, image })
Ok(Made { session, result, thumbnail })
}
pub fn tick(app: &mut SolveApp, ctx: &egui::Context) {
@@ -804,7 +801,9 @@ pub fn tick(app: &mut SolveApp, ctx: &egui::Context) {
crate::documents::adopt(app, made.session);
if request.kind == Kind::Open {
app.home.add_recent(&request.path);
crate::home::install(&mut app.home, ctx, &request.path, made.image);
if made.thumbnail {
crate::home::remember_session(&mut app.home, &app.session);
}
}
}
app.home.open = false;
@@ -1046,7 +1045,7 @@ mod tests {
built: None,
staged: None,
});
tx.send(Ok(Made { session: other, result: json!({"visible":12}), image: None })).unwrap();
tx.send(Ok(Made { session: other, result: json!({"visible":12}), thumbnail: false })).unwrap();
h.frames(2);
assert_eq!(reply_rx.try_recv().unwrap()["result"]["visible"], 12);
assert!(Arc::ptr_eq(&base, &h.app.session.doc));
@@ -1085,7 +1084,7 @@ mod tests {
let newer = app.session.doc.clone();
tick(&mut app, &egui::Context::default());
assert!(app.file_load.running.as_ref().unwrap().preview.is_none());
tx.send(Ok(Made { session: Session::default(), result: Value::Null, image: None })).unwrap();
tx.send(Ok(Made { session: Session::default(), result: Value::Null, thumbnail: false })).unwrap();
tick(&mut app, &egui::Context::default());
assert!(Arc::ptr_eq(&newer, &app.session.doc));
assert!(app.status.as_ref().unwrap().0.contains("discarded"));
@@ -1174,7 +1173,7 @@ mod tests {
assert!(app.file_load.running.is_some());
let mut computed = Session::default();
computed.execute("solid.box", &serde_json::json!({"length":10,"width":10,"height":10})).unwrap();
tx.send(Ok(Made { session: computed, result: Value::Null, image: None })).unwrap();
tx.send(Ok(Made { session: computed, result: Value::Null, thumbnail: false })).unwrap();
tick(&mut app, &egui::Context::default());
assert!(app.file_load.running.is_none());
assert!(Arc::ptr_eq(&old, &app.session.doc));
+2
View File
@@ -211,6 +211,8 @@ fn a_control_open_answers_after_loading_without_freezing_the_window() {
assert_eq!(reply["ok"], true, "{reply}");
assert_eq!(reply["result"], expected);
assert!(count_rx.try_recv().is_ok(), "inspection answered while the file loaded");
// Its Home picture is drawn after it opened, not before.
assert!(crate::home::remembering(&w.app.home), "the Home picture is drawn off the UI thread");
for _ in 0..3 {
w.frame(vec![]);
}
+6 -5
View File
@@ -141,6 +141,12 @@ fn remember_at(s: &Session, #[cfg(not(target_arch = "wasm32"))] identity: Option
Some(img)
}
/// A Home picture is being drawn off the UI thread.
#[cfg(test)]
pub(crate) fn remembering(h: &HomeState) -> bool {
h.remembering.is_some()
}
pub(crate) fn remember_session(h: &mut HomeState, s: &Session) {
#[cfg(not(target_arch = "wasm32"))]
if let Some(path) = &s.path {
@@ -168,11 +174,6 @@ pub(crate) fn remember_session(h: &mut HomeState, s: &Session) {
}
}
pub(crate) fn install(h: &mut HomeState, ctx: &egui::Context, key: &str, img: Option<egui::ColorImage>) {
let tex = img.map(|i| ctx.load_texture(format!("thumb:{key}"), i, egui::TextureOptions::LINEAR));
h.thumbs.insert(key.to_string(), tex);
}
/// Build what a key stands for (runs off the UI thread where threads exist).
fn make(key: &str) -> Made {
#[cfg(not(target_arch = "wasm32"))]