LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Update progress bar, so large lightroom catalog impots do not appear hung
Robert Woldberg48c61e80c163
diff --git a/crates/engine/src/files.rs b/crates/engine/src/files.rsindex db762f009..933de616a 100644--- a/crates/engine/src/files.rs+++ b/crates/engine/src/files.rs@@ -482,9 +482,16 @@ pub(crate) fn decode_raw_preview(bytes: &[u8], opts: lightcraft_codecs::DecodeOp/// Oriented size of the embedded preview of a raw file.fn embedded_preview_size(bytes: &[u8]) -> Option<(u32, u32)> {let jpeg = stand_in_image(bytes)?;- let d = lightcraft_codecs::decode(&jpeg, lightcraft_codecs::DecodeOptions::fit(64, 64)).ok()?;- let (mut w, mut h) = (d.source_width, d.source_height);- if preview_orientation(bytes, d.orientation).swaps_axes() {+ // headers only, as for other images (issue #367): decoding a full-size preview just for its+ // size took about a second per file in an import; a decode remains the fallback+ let (mut w, mut h, orientation) = match lightcraft_codecs::read_header(&jpeg) {+ Ok(header) => (header.width, header.height, header.orientation),+ Err(_) => {+ let d = lightcraft_codecs::decode(&jpeg, lightcraft_codecs::DecodeOptions::fit(64, 64)).ok()?;+ (d.source_width, d.source_height, d.orientation)+ }+ };+ if preview_orientation(bytes, orientation).swaps_axes() {std::mem::swap(&mut w, &mut h);}Some((w, h))diff --git a/crates/engine/src/import.rs b/crates/engine/src/import.rsindex 833d92e8e..8a49ae8ba 100644--- a/crates/engine/src/import.rs+++ b/crates/engine/src/import.rs@@ -412,10 +412,18 @@ pub fn launch_path(arg: &str, cwd: Option<&Path>, home: Option<&Path>, dcim: imp/// Probe files (headers + content hash) as an import would.pub(crate) fn probe_paths(s: &Session, paths: &[String]) -> Vec<Result<ProbeInfo, String>> {- probe_all(s.media.file_probe.as_ref(), paths, &ScanProgress::default())+ let progress = ScanProgress::default();+ probe_all(s.media.file_probe.as_ref(), paths, &progress.done, &progress.cancel)}-fn probe_all(probe: Option<&crate::media::FileProbe>, paths: &[String], progress: &ScanProgress) -> Vec<Result<ProbeInfo, String>> {+/// Probe `paths` (several at once), counting each in `done`. Stops before the next file once+/// `cancel` is set: the files not reached come back as errors.+fn probe_all(+ probe: Option<&crate::media::FileProbe>,+ paths: &[String],+ done: &std::sync::atomic::AtomicUsize,+ cancel: &std::sync::atomic::AtomicBool,+) -> Vec<Result<ProbeInfo, String>> {use std::sync::atomic::Ordering::Relaxed;let Some(probe) = probe.cloned() else {return paths@@ -443,11 +451,11 @@ fn probe_all(probe: Option<&crate::media::FileProbe>, paths: &[String], progressif i >= paths.len() {break;}- if progress.cancel.load(Relaxed) {+ if cancel.load(Relaxed) {break;}let r = probe(&paths[i]);- progress.done.fetch_add(1, Relaxed);+ done.fetch_add(1, Relaxed);out.lock().unwrap_or_else(|e| e.into_inner())[i] = Some(r);}});@@ -459,11 +467,11 @@ fn probe_all(probe: Option<&crate::media::FileProbe>, paths: &[String], progresspaths.iter().map(|p| {- if progress.cancel.load(Relaxed) {+ if cancel.load(Relaxed) {return Err("cancelled".into());}let r = probe(p);- progress.done.fetch_add(1, Relaxed);+ done.fetch_add(1, Relaxed);r}).collect()@@ -565,7 +573,7 @@ pub fn scan_with(mut input: ScanInput, paths: &[String], progress: &ScanProgress.collect();let missing: Vec<String> = todo.iter().zip(&cached).filter(|(_, c)| c.is_none()).map(|(f, _)| f.clone()).collect();progress.done.store(todo.len() - missing.len(), Relaxed);- let mut fresh = probe_all(input.probe.as_ref(), &missing, progress).into_iter();+ let mut fresh = probe_all(input.probe.as_ref(), &missing, &progress.done, &progress.cancel).into_iter();let probed: Vec<Result<ProbeInfo, String>> =cached.into_iter().map(|c| c.map(Ok).unwrap_or_else(|| fresh.next().unwrap_or_else(|| Err("not probed".into())))).collect();crate::memory::release();@@ -650,6 +658,10 @@ pub struct ImportJob {/// Files found so far (folders expanded) and handled so far, for progress.pub total: std::sync::Arc<std::sync::atomic::AtomicUsize>,pub done: std::sync::Arc<std::sync::atomic::AtomicUsize>,+ /// Of those, the files that have to be read first (not probed by a preceding scan) and the+ /// ones read so far: the step before they are handled.+ pub read_total: std::sync::Arc<std::sync::atomic::AtomicUsize>,+ pub read_done: std::sync::Arc<std::sync::atomic::AtomicUsize>,}/// The outcome of [`ImportJob::prepare`] for one batch, in file order.@@ -802,6 +814,8 @@ impl ImportJob {now: (s.clock)(),total: Default::default(),done: Default::default(),+ read_total: Default::default(),+ read_done: Default::default(),})}@@ -853,8 +867,10 @@ impl ImportJob {// files a preceding scan already probed are not read again (a network share is slow to read)let cached: Vec<Option<ProbeInfo>> = todo.iter().map(|f| self.cache.remove(f)).collect();let missing: Vec<String> = todo.iter().zip(&cached).filter(|(_, c)| c.is_none()).map(|(f, _)| f.clone()).collect();- let progress = ScanProgress::default();- let mut fresh = probe_all(self.probe.as_ref(), &missing, &progress).into_iter();+ // Reading the files is the slow part of adding them where they are: it is counted on its+ // own, and `cancel` stops it too (a large library takes long enough to want both).+ self.read_total.fetch_add(missing.len(), Relaxed);+ let mut fresh = probe_all(self.probe.as_ref(), &missing, &self.read_done, cancel).into_iter();let probed: Vec<Result<ProbeInfo, String>> =cached.into_iter().map(|c| c.map(Ok).unwrap_or_else(|| fresh.next().unwrap_or_else(|| Err("not probed".into())))).collect();crate::memory::release();@@ -1412,4 +1428,51 @@ mod prepared_tests {assert!(matches!(prepared.items.first(), Some(PreparedItem::Duplicate { reason: "path", .. })));assert!(matches!(prepared.items.get(1), Some(PreparedItem::Ready(_))));}++ fn unread_paths(n: usize) -> Vec<String> {+ (0..n).map(|i| std::env::temp_dir().join(format!("lightcraft-probe-progress-{i}.jpg")).to_string_lossy().into()).collect()+ }++ /// Reading the files of a large import (a Lightroom catalog's originals) reported nothing:+ /// the progress stood still at "14 of 24554" for as long as it took.+ #[test]+ fn prepare_counts_the_files_it_reads() {+ use std::sync::atomic::Ordering::Relaxed;+ let mut s = Session::new();+ let seen = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));+ let (seen_in_probe, done_in_probe) = (seen.clone(), std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0)));+ let mut job = ImportJob::new(&mut s, ImportOptions { mode: ImportMode::Add, ..ImportOptions::default() }).unwrap();+ let (done, last) = (job.read_done.clone(), done_in_probe.clone());+ job.probe = Some(std::sync::Arc::new(move |_: &str| {+ seen_in_probe.fetch_add(1, Relaxed);+ last.fetch_max(done.load(Relaxed), Relaxed);+ Ok(ProbeInfo { format: "JPEG".into(), ..ProbeInfo::default() })+ }));+ let prepared = job.prepare(&unread_paths(40), &std::sync::atomic::AtomicBool::new(false));+ assert_eq!(prepared.items.len(), 40);+ assert_eq!(seen.load(Relaxed), 40);+ assert!(done_in_probe.load(Relaxed) > 0, "progress moves while files are read");+ assert_eq!((job.read_done.load(Relaxed), job.read_total.load(Relaxed)), (40, 40), "every file read is counted");+ assert_eq!((job.done.load(Relaxed), job.total.load(Relaxed)), (40, 40), "handling them is counted on its own");+ }++ /// Cancel had no effect until every file had been read.+ #[test]+ fn cancel_stops_reading_files() {+ use std::sync::atomic::Ordering::Relaxed;+ let mut s = Session::new();+ let cancel = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));+ let seen = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));+ let mut job = ImportJob::new(&mut s, ImportOptions { mode: ImportMode::Add, ..ImportOptions::default() }).unwrap();+ let (seen_in_probe, cancel_in_probe) = (seen.clone(), cancel.clone());+ job.probe = Some(std::sync::Arc::new(move |_: &str| {+ seen_in_probe.fetch_add(1, Relaxed);+ cancel_in_probe.store(true, Relaxed);+ Ok(ProbeInfo { format: "JPEG".into(), ..ProbeInfo::default() })+ }));+ let prepared = job.prepare(&unread_paths(400), &cancel);+ // at most the files the (up to 8) readers had already started+ assert!(seen.load(Relaxed) <= 8, "read {} files after cancel", seen.load(Relaxed));+ assert!(prepared.items.is_empty());+ }}diff --git a/crates/engine/src/lightroom_job.rs b/crates/engine/src/lightroom_job.rsindex fd939341d..9a0658b48 100644--- a/crates/engine/src/lightroom_job.rs+++ b/crates/engine/src/lightroom_job.rs@@ -129,6 +129,65 @@ pub struct LightroomCompletion {/// Alias used by hosts that call the result a commit.pub type LightroomCommit = LightroomCompletion;+/// The step of preparing a Lightroom import that is under way ([`LightroomProgress::step`]).+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum LightroomStep {+ /// Reading the catalog's tables.+ Catalog,+ /// Reading the photos the catalog names (headers, content hash): nearly all of the time.+ ReadPhotos,+ /// Readying the photos that were read for the catalog.+ AddPhotos,+}++/// Progress of [`LightroomJob::prepare`] step by step, shared with the thread that runs it.+#[derive(Clone, Default)]+pub struct LightroomProgress {+ /// Catalog tables to read and read so far ([`lightroom_catalog::read_with_progress`]).+ pub catalog_total: Arc<AtomicUsize>,+ pub catalog_done: Arc<AtomicUsize>,+ read_total: Arc<AtomicUsize>,+ read_done: Arc<AtomicUsize>,+ add_total: Arc<AtomicUsize>,+ add_done: Arc<AtomicUsize>,+ /// The catalog is read: the photos are next.+ photos: Arc<AtomicBool>,+}++impl LightroomProgress {+ /// Reading the photos is nearly all of an import's time; the catalog and readying the photos+ /// take the rest of [`LightroomProgress::fraction`].+ const CATALOG_SHARE: f32 = 0.05;+ const READ_SHARE: f32 = 0.85;++ /// The step under way, with how much of it is done and its total (0 while not yet known).+ pub fn step(&self) -> (LightroomStep, usize, usize) {+ let load = |n: &AtomicUsize| n.load(Ordering::Relaxed);+ if !self.photos.load(Ordering::Relaxed) {+ return (LightroomStep::Catalog, load(&self.catalog_done), load(&self.catalog_total));+ }+ let (read_done, read_total) = (load(&self.read_done), load(&self.read_total));+ let (add_done, add_total) = (load(&self.add_done), load(&self.add_total));+ // nothing to read (every photo is already in the library) goes straight to adding+ if read_done < read_total || (read_total == 0 && add_done == 0) {+ (LightroomStep::ReadPhotos, read_done, read_total)+ } else {+ (LightroomStep::AddPhotos, add_done, add_total)+ }+ }++ /// The whole preparation, 0..=1.+ pub fn fraction(&self) -> f32 {+ let (step, done, total) = self.step();+ let part = if total == 0 { 0.0 } else { (done as f32 / total as f32).clamp(0.0, 1.0) };+ match step {+ LightroomStep::Catalog => Self::CATALOG_SHARE * part,+ LightroomStep::ReadPhotos => Self::CATALOG_SHARE + Self::READ_SHARE * part,+ LightroomStep::AddPhotos => Self::CATALOG_SHARE + Self::READ_SHARE + (1.0 - Self::CATALOG_SHARE - Self::READ_SHARE) * part,+ }+ }+}+/// A Lightroom import detached from the owner thread.pub struct LightroomJob {path: PathBuf,@@ -136,6 +195,7 @@ pub struct LightroomJob {import: ImportJob,token: LightroomLibraryToken,archive_dir: Option<PathBuf>,+ progress: LightroomProgress,}impl LightroomJob {@@ -144,33 +204,25 @@ impl LightroomJob {let opts = ImportOptions { mode: ImportMode::Add, ..ImportOptions::default() };let import = ImportJob::new(s, opts)?;let archive_dir = s.library.as_ref().filter(|library| library.on_disk).map(|library| library.dir.join("Interop"));- Ok(Self { path, update_existing, import, token: LightroomLibraryToken::capture(s), archive_dir })- }-- pub fn total(&self) -> usize {- self.import.total.load(Ordering::Relaxed)- }-- pub fn done(&self) -> usize {- self.import.done.load(Ordering::Relaxed)+ let progress = LightroomProgress {+ read_total: Arc::clone(&import.read_total),+ read_done: Arc::clone(&import.read_done),+ add_total: Arc::clone(&import.total),+ add_done: Arc::clone(&import.done),+ ..LightroomProgress::default()+ };+ Ok(Self { path, update_existing, import, token: LightroomLibraryToken::capture(s), archive_dir, progress })}- pub fn progress(&self) -> (usize, usize) {- (self.done(), self.total())+ /// The job's progress, to watch from another thread while [`LightroomJob::prepare`] runs.+ pub fn progress(&self) -> LightroomProgress {+ self.progress.clone()}pub fn token(&self) -> &LightroomLibraryToken {&self.token}- pub fn total_atomic(&self) -> std::sync::Arc<AtomicUsize> {- std::sync::Arc::clone(&self.import.total)- }-- pub fn done_atomic(&self) -> std::sync::Arc<AtomicUsize> {- std::sync::Arc::clone(&self.import.done)- }-/// Finish an owner commit's deferred archive-index write on a worker.pub fn finish_archive(finalization: LightroomArchiveFinalization) -> crate::Result<()> {finalization.finish()@@ -181,14 +233,12 @@ impl LightroomJob {if cancel.load(Ordering::Relaxed) {return Err(error("Lightroom import cancelled"));}- self.import.total.store(1, Ordering::Relaxed);- self.import.done.store(0, Ordering::Relaxed);- let mut data = lightroom_catalog::read_with_progress(&self.path, cancel, &self.import.total, &self.import.done).map_err(error)?;+ let mut data =+ lightroom_catalog::read_with_progress(&self.path, cancel, &self.progress.catalog_total, &self.progress.catalog_done).map_err(error)?;lightroom_catalog::validate_for_job(&data).map_err(error)?;if cancel.load(Ordering::Relaxed) {return Err(error("Lightroom import cancelled"));}- self.import.done.fetch_add(1, Ordering::Relaxed);let paths: Vec<String> = data.photos.iter()@@ -202,6 +252,9 @@ impl LightroomJob {.filter(|photo| !Path::new(&photo.path).is_file()).map(|photo| normalize(&photo.path)).collect();+ // the catalog step's last unit (validation, and looking for each original), then the photos+ self.progress.catalog_done.fetch_add(1, Ordering::Relaxed);+ self.progress.photos.store(true, Ordering::Relaxed);let normal = self.import.prepare(&paths, cancel);if cancel.load(Ordering::Relaxed) {normal.rollback();@@ -334,6 +387,48 @@ mod tests {}}+ /// One count for the whole import read "14 of 24554" while the photos were read, then twice+ /// the number of photos: each step has its own count, and the whole only moves forward.+ #[test]+ fn progress_names_each_step_with_its_own_count() {+ let p = LightroomProgress::default();+ let set = |n: &AtomicUsize, v: usize| n.store(v, Ordering::Relaxed);+ assert_eq!(p.step(), (LightroomStep::Catalog, 0, 0));+ assert_eq!(p.fraction(), 0.0);+ set(&p.catalog_total, 14);+ set(&p.catalog_done, 7);+ assert_eq!(p.step(), (LightroomStep::Catalog, 7, 14));+ let mut last = p.fraction();+ assert!(last > 0.0);+ let mut forward = |p: &LightroomProgress| {+ let f = p.fraction();+ assert!(f >= last && f <= 1.0, "{f} after {last}");+ last = f;+ };+ set(&p.catalog_done, 14);+ p.photos.store(true, Ordering::Relaxed);+ assert_eq!(p.step(), (LightroomStep::ReadPhotos, 0, 0), "the photos are not counted yet");+ forward(&p);+ set(&p.add_total, 100);+ set(&p.read_total, 100);+ set(&p.read_done, 40);+ assert_eq!(p.step(), (LightroomStep::ReadPhotos, 40, 100));+ forward(&p);+ set(&p.read_done, 100);+ set(&p.add_done, 25);+ assert_eq!(p.step(), (LightroomStep::AddPhotos, 25, 100));+ forward(&p);+ set(&p.add_done, 100);+ forward(&p);+ assert!(p.fraction() > 0.999);+ // every photo already in the library: nothing to read+ let known = LightroomProgress::default();+ known.photos.store(true, Ordering::Relaxed);+ set(&known.add_total, 5);+ set(&known.add_done, 5);+ assert_eq!(known.step(), (LightroomStep::AddPhotos, 5, 5));+ }+#[test]fn cancellation_before_commit_leaves_owner_catalog_unchanged() {let mut session = crate::Session::new();diff --git a/crates/ui-egui/src/lightroom_import.rs b/crates/ui-egui/src/lightroom_import.rsindex 8cee63e39..774e92d8b 100644--- a/crates/ui-egui/src/lightroom_import.rs+++ b/crates/ui-egui/src/lightroom_import.rs@@ -5,10 +5,11 @@//! data only on the owner thread, then finishes the archive index on a worker.use std::path::PathBuf;-use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};+use std::sync::atomic::{AtomicBool, Ordering};use std::sync::{Arc, mpsc};use egui::Align2;+use lightcraft_engine::lightroom_job::{LightroomProgress, LightroomStep};use serde_json::{Value, json};use crate::LightcraftApp;@@ -39,8 +40,7 @@ pub struct LightroomTask {kind: Kind,path: PathBuf,cancel: Arc<AtomicBool>,- total: Arc<AtomicUsize>,- done: Arc<AtomicUsize>,+ progress: LightroomProgress,rx: mpsc::Receiver<Message>,phase: Phase,cancelled: bool,@@ -58,13 +58,21 @@ impl LightroomTask {Phase::Committing => "committing",Phase::Finalizing => "finalizing",};+ let (step, done, total) = self.progress.step();+ let step = match step {+ LightroomStep::Catalog => "catalog",+ LightroomStep::ReadPhotos => "readPhotos",+ LightroomStep::AddPhotos => "addPhotos",+ };json!({"running": true,"kind": kind,"path": self.path,"phase": phase,- "done": self.done.load(Ordering::Relaxed),- "total": self.total.load(Ordering::Relaxed),+ "step": step,+ "done": done,+ "total": total,+ "fraction": self.progress.fraction(),"cancelled": self.cancelled || self.cancel.load(Ordering::Relaxed),})}@@ -106,8 +114,7 @@ fn busy(app: &LightcraftApp) -> Result<(), String> {fn spawn_inspect(path: PathBuf,cancel: Arc<AtomicBool>,- total: Arc<AtomicUsize>,- done: Arc<AtomicUsize>,+ progress: LightroomProgress,tx: mpsc::Sender<Message>,ctx: egui::Context,) -> Result<(), String> {@@ -115,7 +122,7 @@ fn spawn_inspect(.name("lc-lightroom-inspect".into()).spawn(move || {let result = lightcraft_engine::guard::catch("Lightroom inspect", || {- lightcraft_engine::lightroom_catalog::read_with_progress(&path, &cancel, &total, &done)+ lightcraft_engine::lightroom_catalog::read_with_progress(&path, &cancel, &progress.catalog_total, &progress.catalog_done)}).and_then(|r| r.map(inspect_report));let _ = tx.send(Message::Inspected(result));@@ -231,12 +238,11 @@ fn terminal(app: &mut LightcraftApp, ctx: &egui::Context, kind: Kind, value: Valfn start_inspect(app: &mut LightcraftApp, path: PathBuf, ctx: &egui::Context) -> Result<Value, String> {busy(app)?;let cancel = Arc::new(AtomicBool::new(false));- let total = Arc::new(AtomicUsize::new(0));- let done = Arc::new(AtomicUsize::new(0));+ let progress = LightroomProgress::default();let (tx, rx) = mpsc::channel();- spawn_inspect(path.clone(), cancel.clone(), total.clone(), done.clone(), tx, ctx.clone())?;+ spawn_inspect(path.clone(), cancel.clone(), progress.clone(), tx, ctx.clone())?;app.lightroom_last = None;- app.lightroom = Some(LightroomTask { kind: Kind::Inspect, path: path.clone(), cancel, total, done, rx, phase: Phase::Reading, cancelled: false });+ app.lightroom = Some(LightroomTask { kind: Kind::Inspect, path: path.clone(), cancel, progress, rx, phase: Phase::Reading, cancelled: false });Ok(json!({"running": true, "kind": "inspect", "path": path}))}@@ -245,12 +251,11 @@ fn start_import(app: &mut LightcraftApp, path: PathBuf, update_existing: bool, cbusy(app)?;let job = lightcraft_engine::lightroom_job::LightroomJob::new(&mut app.session, path.clone(), update_existing).map_err(|e| e.to_string())?;let cancel = Arc::new(AtomicBool::new(false));- let total = job.total_atomic();- let done = job.done_atomic();+ let progress = job.progress();let (tx, rx) = mpsc::channel();spawn_prepare(job, cancel.clone(), tx, ctx.clone())?;app.lightroom_last = None;- app.lightroom = Some(LightroomTask { kind: Kind::Import, path: path.clone(), cancel, total, done, rx, phase: Phase::Reading, cancelled: false });+ app.lightroom = Some(LightroomTask { kind: Kind::Import, path: path.clone(), cancel, progress, rx, phase: Phase::Reading, cancelled: false });Ok(json!({"running": true, "kind": "import", "path": path}))}@@ -412,25 +417,43 @@ pub fn wait_for(_app: &mut LightcraftApp, _ctx: &egui::Context, _timeout: std::t/// The progress window for inspect/import, with cancellation.pub fn progress(app: &mut LightcraftApp, ctx: &egui::Context) {let Some(task) = app.lightroom.as_ref() else { return };- let total = task.total.load(Ordering::Relaxed);- let done = task.done.load(Ordering::Relaxed);+ let (step, done, total) = task.progress.step();let title = match task.kind {Kind::Inspect => crate::i18n::tr("Inspecting Lightroom Catalog"),Kind::Import => crate::i18n::tr("Importing Lightroom Catalog"),};- let text = match task.phase {- Phase::Reading if total == 0 => crate::i18n::tr("Reading Lightroom catalog…").into(),- Phase::Reading => crate::i18n::tr_format!("Reading Lightroom catalog… {done} of {total}", done = done, total = total),- Phase::Committing => crate::i18n::tr("Adding Lightroom photos…").into(),- Phase::Finalizing => crate::i18n::tr("Saving Lightroom import index…").into(),+ // The step under way, with its own count: reading the photos takes nearly all of an import.+ let text = match (task.phase, step) {+ (Phase::Reading, LightroomStep::Catalog) if total == 0 => crate::i18n::tr("Reading Lightroom catalog…").into(),+ (Phase::Reading, LightroomStep::Catalog) => {+ crate::i18n::tr_format!("Reading Lightroom catalog… {done} of {total}", done = done, total = total)+ }+ (Phase::Reading, LightroomStep::ReadPhotos) => crate::i18n::tr_format!("Reading photos… {} of {}", done, total),+ (Phase::Reading, LightroomStep::AddPhotos) => crate::i18n::tr_format!("Adding photos… {} of {}", done, total),+ (Phase::Committing, _) => crate::i18n::tr("Adding Lightroom photos…").into(),+ (Phase::Finalizing, _) => crate::i18n::tr("Saving Lightroom import index…").into(),+ };+ // Two bars: the whole task above, the step named by `text` below. Inspecting is one step.+ let reading = task.phase == Phase::Reading;+ let step_fraction = if reading { done as f32 / total.max(1) as f32 } else { 1.0 };+ let whole = match task.kind {+ Kind::Import if reading => Some(task.progress.fraction()),+ Kind::Import => Some(1.0),+ Kind::Inspect => None,};let mut cancel = false;let t = Tokens::get(ctx);- egui::Window::new(title).title_bar(false).resizable(false).anchor(Align2::CENTER_BOTTOM, [0.0, -80.0]).fixed_size([360.0, 92.0]).show(+ let height = if whole.is_some() { 140.0 } else { 92.0 };+ egui::Window::new(title).title_bar(false).resizable(false).anchor(Align2::CENTER_BOTTOM, [0.0, -80.0]).fixed_size([360.0, height]).show(ctx,|ui| {+ if let Some(whole) = whole {+ ui.label(egui::RichText::new(title).color(t.text).strong());+ ui.add(egui::ProgressBar::new(whole).desired_width(340.0).show_percentage());+ ui.add_space(4.0);+ }ui.label(egui::RichText::new(text).color(t.text));- ui.add(egui::ProgressBar::new(done as f32 / total.max(1) as f32).desired_width(340.0));+ ui.add(egui::ProgressBar::new(step_fraction).desired_width(340.0));let r =ui.add_enabled(task.phase == Phase::Reading && !task.cancel.load(Ordering::Relaxed), egui::Button::new(crate::i18n::tr("Cancel")));register(ui.ctx(), "button:lightroomCancel", r.rect);