Skip to content

Commit c2954ba

Browse files
feat(installation): add a new notification for the progress bar to show a component was installed
1 parent 38bc99b commit c2954ba

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

src/cli/download_tracker.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ impl DownloadTracker {
7777
self.installing_component(component);
7878
true
7979
}
80+
Notification::Install(In::ComponentInstalled(component, _, _)) => {
81+
self.component_installed(component);
82+
true
83+
}
8084
_ => false,
8185
}
8286
}
@@ -132,7 +136,6 @@ impl DownloadTracker {
132136
ProgressStyle::with_template("{msg:>12.bold} downloaded {total_bytes} in {elapsed}")
133137
.unwrap(),
134138
);
135-
pb.finish();
136139
}
137140

138141
/// Notifies self that the download has failed.
@@ -156,7 +159,7 @@ impl DownloadTracker {
156159
pb.set_style(ProgressStyle::with_template("{msg:>12.bold} retrying download").unwrap());
157160
}
158161

159-
/// Notifies that the downloaded component is being installed.
162+
/// Notifies self that the component is being installed.
160163
pub(crate) fn installing_component(&mut self, component: &str) {
161164
let key = self
162165
.file_progress_bars
@@ -168,7 +171,28 @@ impl DownloadTracker {
168171
{
169172
pb.set_style(
170173
ProgressStyle::with_template(
171-
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} installing now...",
174+
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} installing now {spinner:.green}",
175+
)
176+
.unwrap()
177+
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "),
178+
);
179+
pb.enable_steady_tick(Duration::from_millis(100));
180+
}
181+
}
182+
183+
/// Notifies self that the component has been installed.
184+
pub(crate) fn component_installed(&mut self, component: &str) {
185+
let key = self
186+
.file_progress_bars
187+
.keys()
188+
.find(|comp| comp.contains(component))
189+
.cloned();
190+
if let Some(key) = key
191+
&& let Some((pb, _)) = self.file_progress_bars.get(&key)
192+
{
193+
pb.set_style(
194+
ProgressStyle::with_template(
195+
"{msg:>12.bold} downloaded {total_bytes} and installed",
172196
)
173197
.unwrap(),
174198
);

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)