fix some progressbar issues
This commit is contained in:
parent
686e0c3e5c
commit
a8ff354a51
1 changed files with 24 additions and 28 deletions
|
|
@ -58,37 +58,34 @@ impl AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_progressbar(&self, drop_bar: bool, f: impl FnOnce(&ProgressBar)) {
|
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();
|
let mut slot = self.progress.borrow_mut();
|
||||||
if slot.is_none() {
|
let bar = &*slot.get_or_insert_with(|| {
|
||||||
let bar = ProgressBar::no_length()
|
ProgressBar::no_length().with_style(
|
||||||
.with_style(
|
ProgressStyle::with_template(&format!(
|
||||||
ProgressStyle::with_template(&format!(
|
concat!(
|
||||||
concat!(
|
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ",
|
||||||
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ",
|
"{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ",
|
||||||
"{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ",
|
"({{eta}})",
|
||||||
"({{eta}})",
|
),
|
||||||
),
|
style("/").magenta(),
|
||||||
style("/").magenta(),
|
))
|
||||||
))
|
.expect("style template is not valid"),
|
||||||
.expect("style template is not valid"),
|
)
|
||||||
)
|
});
|
||||||
.with_message(upl.get_name().to_owned());
|
|
||||||
|
|
||||||
bar.enable_steady_tick(Duration::from_millis(100));
|
if let Some(upl) = self.inner.peek_uploading() {
|
||||||
*slot = Some(bar);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
f(bar);
|
f(bar);
|
||||||
|
|
||||||
if drop_bar {
|
if drop_bar {
|
||||||
|
|
@ -162,7 +159,6 @@ impl AppState {
|
||||||
self.http
|
self.http
|
||||||
.share_create(&args.get_uri(), &args.alias, args.get_share_request())?;
|
.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)))
|
Ok(Self::new(self.http, CacheFile::from_args(args, share_id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue