Skip to content

Commit c4b68b2

Browse files
feat(installation): add a new notification for the progress bar to show a component was installed
1 parent 8553d1a commit c4b68b2

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/cli/download_tracker.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
22
use std::collections::HashMap;
3+
use std::time::Duration;
34

45
use crate::dist::Notification as In;
56
use crate::notifications::Notification;
@@ -63,6 +64,10 @@ impl DownloadTracker {
6364
self.installing_component(component);
6465
true
6566
}
67+
Notification::Install(In::ComponentInstalled(component, _, _)) => {
68+
self.component_installed(component);
69+
true
70+
}
6671
_ => false,
6772
}
6873
}
@@ -106,10 +111,9 @@ impl DownloadTracker {
106111
ProgressStyle::with_template("{msg:>12.bold} downloaded {total_bytes} in {elapsed}")
107112
.unwrap(),
108113
);
109-
pb.finish();
110114
}
111115

112-
/// Notifies that the downloaded component is being installed.
116+
/// Notifies self that the component is being installed.
113117
pub(crate) fn installing_component(&mut self, component: &str) {
114118
let key = self
115119
.file_progress_bars
@@ -121,7 +125,28 @@ impl DownloadTracker {
121125
{
122126
pb.set_style(
123127
ProgressStyle::with_template(
124-
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} installing now...",
128+
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} installing now {spinner:.green}",
129+
)
130+
.unwrap()
131+
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "),
132+
);
133+
pb.enable_steady_tick(Duration::from_millis(100));
134+
}
135+
}
136+
137+
/// Notifies self that the component has been installed.
138+
pub(crate) fn component_installed(&mut self, component: &str) {
139+
let key = self
140+
.file_progress_bars
141+
.keys()
142+
.find(|comp| comp.contains(component))
143+
.cloned();
144+
if let Some(key) = key
145+
&& let Some(pb) = self.file_progress_bars.get(&key)
146+
{
147+
pb.set_style(
148+
ProgressStyle::with_template(
149+
"{msg:>12.bold} downloaded {total_bytes} and installed",
125150
)
126151
.unwrap(),
127152
);

src/dist/manifestation.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl Manifestation {
271271
match message {
272272
Ok((component, format, installer_file)) => {
273273
match self.install_component(
274-
component,
274+
component.clone(),
275275
format,
276276
installer_file,
277277
tmp_cx,
@@ -280,6 +280,13 @@ impl Manifestation {
280280
current_tx,
281281
) {
282282
Ok(new_tx) => {
283+
(download_cfg.notify_handler)(
284+
Notification::ComponentInstalled(
285+
&component.short_name(new_manifest),
286+
&self.target_triple,
287+
Some(&self.target_triple),
288+
),
289+
);
283290
current_tx = new_tx;
284291
}
285292
Err(e) => {

src/dist/notifications.rs

Lines changed: 9 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),
@@ -64,6 +65,7 @@ impl Notification<'_> {
6465
Extracting(_, _)
6566
| DownloadingComponent(_, _, _, _)
6667
| InstallingComponent(_, _, _)
68+
| ComponentInstalled(_, _, _)
6769
| RemovingComponent(_, _, _)
6870
| RemovingOldComponent(_, _, _)
6971
| ComponentAlreadyInstalled(_)
@@ -122,6 +124,13 @@ impl Display for Notification<'_> {
122124
write!(f, "installing component '{}' for '{}'", c, t.unwrap())
123125
}
124126
}
127+
ComponentInstalled(c, h, t) => {
128+
if Some(h) == t.as_ref() || t.is_none() {
129+
write!(f, "installing component '{c}'")
130+
} else {
131+
write!(f, "installing component '{}' for '{}'", c, t.unwrap())
132+
}
133+
}
125134
RemovingComponent(c, h, t) => {
126135
if Some(h) == t.as_ref() || t.is_none() {
127136
write!(f, "removing component '{c}'")

0 commit comments

Comments
 (0)