From 54b1dfbe4bd559861034db5fe6dfec3054e54a43 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Tue, 14 Aug 2018 17:08:43 +0200 Subject: [PATCH] Load the albums list first and use its length as a progress range estimation --- src/main.rs | 11 +++++++---- src/registry.rs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5d9b5f9..21cee82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,18 +49,21 @@ fn main() -> Result<(), Error> { } fn load_albums(ui: &mut Cursive) { + let mut registry = REGISTRY.lock().unwrap(); + if let Err(error) = registry.load_albums_file() { + eprintln!("Something went wrong: {}", error); + quit(ui); + } + let cb = ui.cb_sink().clone(); ui.add_layer( Dialog::around(ProgressBar::new() - .range(0, 603) // FIXME: No idea what to put here. + .range(0, registry.albums_list.len()) .with_task(move |counter| { let mut registry = REGISTRY.lock().unwrap(); if let Err(error) = registry.load_albums_fs(&counter) { eprintln!("Something went wrong: {}", error); cb.send(Box::new(quit)); - } else if let Err(error) = registry.load_albums_file() { - eprintln!("Something went wrong: {}", error); - cb.send(Box::new(quit)); } else { cb.send(Box::new(select_albums)); } diff --git a/src/registry.rs b/src/registry.rs index f989840..00a0c04 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -40,7 +40,7 @@ impl Registry { )); counter.tick(1); } - counter.set(603); + counter.set(self.albums_fs.len()); Ok(()) }