-
Notifications
You must be signed in to change notification settings - Fork 979
Interleave downloads with installations when downloading a toolchain #4471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9ff199a
2ad06c8
c1d1bbc
2150965
acfc43b
4ed8bb2
750c216
399b575
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,14 @@ impl DownloadTracker { | |
self.retrying_download(url); | ||
true | ||
} | ||
Notification::InstallingComponent(component, _, _) => { | ||
self.installing_component(component); | ||
true | ||
} | ||
Notification::ComponentInstalled(component, _, _) => { | ||
self.component_installed(component); | ||
true | ||
} | ||
_ => false, | ||
} | ||
} | ||
|
@@ -120,10 +128,13 @@ impl DownloadTracker { | |
return; | ||
}; | ||
pb.set_style( | ||
ProgressStyle::with_template("{msg:>12.bold} downloaded {total_bytes} in {elapsed}") | ||
.unwrap(), | ||
ProgressStyle::with_template(if pb.position() != 0 { | ||
"{msg:>12.bold} downloaded {total_bytes} in {elapsed}" | ||
} else { | ||
"{msg:>12.bold} component already downloaded" | ||
}) | ||
.unwrap(), | ||
Comment on lines
+131
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again there's a lot of duplication here, suggest adding a little abstraction to make it more obvious what happens here. |
||
); | ||
pb.finish(); | ||
} | ||
|
||
/// Notifies self that the download has failed. | ||
|
@@ -146,4 +157,50 @@ impl DownloadTracker { | |
*retry_time = Some(Instant::now()); | ||
pb.set_style(ProgressStyle::with_template("{msg:>12.bold} retrying download").unwrap()); | ||
} | ||
|
||
/// Notifies self that the component is being installed. | ||
pub(crate) fn installing_component(&mut self, component: &str) { | ||
let key = self | ||
.file_progress_bars | ||
.keys() | ||
.find(|comp| comp.contains(component)) | ||
.cloned(); | ||
if let Some(key) = key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: invert these for early returns. |
||
&& let Some((pb, _)) = self.file_progress_bars.get(&key) | ||
{ | ||
pb.set_style( | ||
ProgressStyle::with_template( if pb.position() != 0 { | ||
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} and installing {spinner:.green}" | ||
} else { | ||
"{msg:>12.bold} component already downloaded and installing {spinner:.green}" | ||
} | ||
) | ||
.unwrap() | ||
.tick_chars(r"|/-\ "), | ||
); | ||
pb.enable_steady_tick(Duration::from_millis(100)); | ||
} | ||
} | ||
|
||
/// Notifies self that the component has been installed. | ||
pub(crate) fn component_installed(&mut self, component: &str) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we share the duplicate code? |
||
let key = self | ||
.file_progress_bars | ||
.keys() | ||
.find(|comp| comp.contains(component)) | ||
.cloned(); | ||
if let Some(key) = key | ||
&& let Some((pb, _)) = self.file_progress_bars.get(&key) | ||
{ | ||
pb.set_style( | ||
ProgressStyle::with_template(if pb.position() != 0 { | ||
"{msg:>12.bold} downloaded {total_bytes} and installed" | ||
} else { | ||
"{msg:>12.bold} component already downloaded and installed" | ||
}) | ||
.unwrap(), | ||
); | ||
pb.finish(); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.