Load the albums list first and use its length as a progress range estimation

master
Paul van Tilburg 4 years ago
parent 0e4286cf83
commit 54b1dfbe4b
  1. 11
      src/main.rs
  2. 2
      src/registry.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));
}

@ -40,7 +40,7 @@ impl Registry {
));
counter.tick(1);
}
counter.set(603);
counter.set(self.albums_fs.len());
Ok(())
}