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

This commit is contained in:
Paul van Tilburg 2018-08-14 17:08:43 +02:00
parent 0e4286cf83
commit 54b1dfbe4b
2 changed files with 8 additions and 5 deletions

View File

@ -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));
}

View File

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