fix some progressbar issues
This commit is contained in:
parent
686e0c3e5c
commit
e61214a589
1 changed files with 24 additions and 28 deletions
|
|
@ -58,36 +58,33 @@ impl AppState {
|
|||
}
|
||||
|
||||
fn with_progressbar(&self, drop_bar: bool, f: impl FnOnce(&ProgressBar)) {
|
||||
let Some(upl) = self.inner.peek_uploading() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut slot = self.progress.borrow_mut();
|
||||
if slot.is_none() {
|
||||
let bar = ProgressBar::no_length()
|
||||
.with_style(
|
||||
ProgressStyle::with_template(&format!(
|
||||
concat!(
|
||||
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ",
|
||||
"{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ",
|
||||
"({{eta}})",
|
||||
),
|
||||
style("/").magenta(),
|
||||
))
|
||||
.expect("style template is not valid"),
|
||||
)
|
||||
.with_message(upl.get_name().to_owned());
|
||||
let bar = &*slot.get_or_insert_with(|| {
|
||||
ProgressBar::no_length().with_style(
|
||||
ProgressStyle::with_template(&format!(
|
||||
concat!(
|
||||
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ",
|
||||
"{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ",
|
||||
"({{eta}})",
|
||||
),
|
||||
style("/").magenta(),
|
||||
))
|
||||
.expect("style template is not valid"),
|
||||
)
|
||||
});
|
||||
|
||||
bar.enable_steady_tick(Duration::from_millis(100));
|
||||
*slot = Some(bar);
|
||||
}
|
||||
if let Some(upl) = self.inner.peek_uploading() {
|
||||
if bar.length().is_none() {
|
||||
bar.set_length(upl.get_size());
|
||||
bar.set_message(upl.get_name().to_owned());
|
||||
bar.enable_steady_tick(Duration::from_millis(100));
|
||||
}
|
||||
|
||||
let bar = slot.as_ref().expect("somehow the slot holds None");
|
||||
|
||||
bar.set_position(upl.get_offset());
|
||||
// BUG in `indicatif` crate?
|
||||
// `set_position` does not force an immediate redraw, so we need to call `set_length` after
|
||||
bar.set_length(upl.get_size());
|
||||
bar.set_position(upl.get_offset());
|
||||
// BUG in `indicatif` crate?
|
||||
// `set_position` does not force an immediate redraw, so we also call `inc_length` here
|
||||
bar.inc_length(0);
|
||||
};
|
||||
|
||||
f(bar);
|
||||
|
||||
|
|
@ -162,7 +159,6 @@ impl AppState {
|
|||
self.http
|
||||
.share_create(&args.get_uri(), &args.alias, args.get_share_request())?;
|
||||
|
||||
self.with_progressbar(true, ProgressBar::abandon);
|
||||
Ok(Self::new(self.http, CacheFile::from_args(args, share_id)))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue