Skip to content

Commit ffff3e8

Browse files
feat(installations): add a new notification for the progress bar to show a component was installed
1 parent c1d1bbc commit ffff3e8

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/cli/download_tracker.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ impl DownloadTracker {
6868
self.retrying_download(url);
6969
true
7070
}
71-
Notification::Install(In::InstallingComponent(component, _, _)) => {
71+
Notification::InstallingComponent(component, _, _) => {
7272
self.installing_component(component);
7373
true
7474
}
75+
Notification::ComponentInstalled(component, _, _) => {
76+
self.component_installed(component);
77+
true
78+
}
7579
_ => false,
7680
}
7781
}
@@ -127,7 +131,6 @@ impl DownloadTracker {
127131
ProgressStyle::with_template("{msg:>12.bold} downloaded {total_bytes} in {elapsed}")
128132
.unwrap(),
129133
);
130-
pb.finish();
131134
}
132135

133136
/// Notifies self that the download has failed.
@@ -151,7 +154,7 @@ impl DownloadTracker {
151154
pb.set_style(ProgressStyle::with_template("{msg:>12.bold} retrying download").unwrap());
152155
}
153156

154-
/// Notifies that the downloaded component is being installed.
157+
/// Notifies self that the component is being installed.
155158
pub(crate) fn installing_component(&mut self, component: &str) {
156159
let key = self
157160
.file_progress_bars
@@ -163,7 +166,28 @@ impl DownloadTracker {
163166
{
164167
pb.set_style(
165168
ProgressStyle::with_template(
166-
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} installing now...",
169+
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} installing now {spinner:.green}",
170+
)
171+
.unwrap()
172+
.tick_chars(r"|/-\ "),
173+
);
174+
pb.enable_steady_tick(Duration::from_millis(100));
175+
}
176+
}
177+
178+
/// Notifies self that the component has been installed.
179+
pub(crate) fn component_installed(&mut self, component: &str) {
180+
let key = self
181+
.file_progress_bars
182+
.keys()
183+
.find(|comp| comp.contains(component))
184+
.cloned();
185+
if let Some(key) = key
186+
&& let Some((pb, _)) = self.file_progress_bars.get(&key)
187+
{
188+
pb.set_style(
189+
ProgressStyle::with_template(
190+
"{msg:>12.bold} downloaded {total_bytes} and installed",
167191
)
168192
.unwrap(),
169193
);

src/dist/manifestation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ impl Manifestation {
271271
&& let Some(message) = download_rx.recv().await
272272
{
273273
let (component_bin, installer_file) = message?;
274+
let short_name = component_bin.component.short_name(new_manifest);
274275
current_tx = self.install_component(
275276
component_bin,
276277
installer_file,
@@ -279,6 +280,11 @@ impl Manifestation {
279280
new_manifest,
280281
current_tx,
281282
)?;
283+
(download_cfg.notify_handler)(Notification::ComponentInstalled(
284+
&short_name,
285+
&self.target_triple,
286+
Some(&self.target_triple),
287+
));
282288
counter += 1;
283289
}
284290
Ok::<_, Error>(current_tx)

src/notifications.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub enum Notification<'a> {
2626
/// The URL of the download is passed as the last argument, to allow us to track concurrent downloads.
2727
DownloadingComponent(&'a str, &'a TargetTriple, Option<&'a TargetTriple>, &'a str),
2828
InstallingComponent(&'a str, &'a TargetTriple, Option<&'a TargetTriple>),
29+
ComponentInstalled(&'a str, &'a TargetTriple, Option<&'a TargetTriple>),
2930
RemovingComponent(&'a str, &'a TargetTriple, Option<&'a TargetTriple>),
3031
RemovingOldComponent(&'a str, &'a TargetTriple, Option<&'a TargetTriple>),
3132
DownloadingManifest(&'a str),
@@ -106,6 +107,7 @@ impl Notification<'_> {
106107
Extracting(_, _)
107108
| DownloadingComponent(_, _, _, _)
108109
| InstallingComponent(_, _, _)
110+
| ComponentInstalled(_, _, _)
109111
| RemovingComponent(_, _, _)
110112
| RemovingOldComponent(_, _, _)
111113
| ComponentAlreadyInstalled(_)
@@ -201,6 +203,12 @@ impl Display for Notification<'_> {
201203
write!(f, "installing component '{}' for '{}'", c, t.unwrap())
202204
}
203205
}
206+
ComponentInstalled(c, h, t) => {
207+
match t {
208+
Some(t) if t != h => write!(f, "component '{c}' for '{t}' installed"),
209+
_ => write!(f, "component '{c}' installed"),
210+
}
211+
}
204212
RemovingComponent(c, h, t) => {
205213
if Some(h) == t.as_ref() || t.is_none() {
206214
write!(f, "removing component '{c}'")

0 commit comments

Comments
 (0)