Skip to content

Commit 0b18ec7

Browse files
SomeoneToIgnorenoaccOS
authored andcommitted
Allow clearning activity indicators on click (zed-industries#18305)
All indicators without the click action are now could be hidden with a click. Sometimes, I see a few language server updates statuses get stuck due to npm desperately attempting to access its registry (3 times per each package, with the timeout a bit under 1 minute per each request). So, while the message seems stuck, npm desperately tries to do some work in the background. https://docs.npmjs.com/cli/v10/using-npm/config has options for timeouts & retries for __package fetching__ but that does not include the actual __registry access attempts__. It's unclear how to proceed with npm on this case now, but at least we should allow hiding these redundant messages. Release Notes: - Improved activity indicators' UX by allowing more of them to be hidden on click
1 parent 1e75212 commit 0b18ec7

File tree

1 file changed

+59
-13
lines changed

1 file changed

+59
-13
lines changed

crates/activity_indicator/src/activity_indicator.rs

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ impl ActivityIndicator {
227227
for status in &self.statuses {
228228
match status.status {
229229
LanguageServerBinaryStatus::CheckingForUpdate => {
230-
checking_for_update.push(status.name.0.as_ref())
230+
checking_for_update.push(status.name.clone())
231231
}
232-
LanguageServerBinaryStatus::Downloading => downloading.push(status.name.0.as_ref()),
233-
LanguageServerBinaryStatus::Failed { .. } => failed.push(status.name.0.as_ref()),
232+
LanguageServerBinaryStatus::Downloading => downloading.push(status.name.clone()),
233+
LanguageServerBinaryStatus::Failed { .. } => failed.push(status.name.clone()),
234234
LanguageServerBinaryStatus::None => {}
235235
}
236236
}
@@ -242,8 +242,24 @@ impl ActivityIndicator {
242242
.size(IconSize::Small)
243243
.into_any_element(),
244244
),
245-
message: format!("Downloading {}...", downloading.join(", "),),
246-
on_click: None,
245+
message: format!(
246+
"Downloading {}...",
247+
downloading.iter().map(|name| name.0.as_ref()).fold(
248+
String::new(),
249+
|mut acc, s| {
250+
if !acc.is_empty() {
251+
acc.push_str(", ");
252+
}
253+
acc.push_str(s);
254+
acc
255+
}
256+
)
257+
),
258+
on_click: Some(Arc::new(move |this, cx| {
259+
this.statuses
260+
.retain(|status| !downloading.contains(&status.name));
261+
this.dismiss_error_message(&DismissErrorMessage, cx)
262+
})),
247263
});
248264
}
249265

@@ -256,9 +272,22 @@ impl ActivityIndicator {
256272
),
257273
message: format!(
258274
"Checking for updates to {}...",
259-
checking_for_update.join(", "),
275+
checking_for_update.iter().map(|name| name.0.as_ref()).fold(
276+
String::new(),
277+
|mut acc, s| {
278+
if !acc.is_empty() {
279+
acc.push_str(", ");
280+
}
281+
acc.push_str(s);
282+
acc
283+
}
284+
),
260285
),
261-
on_click: None,
286+
on_click: Some(Arc::new(move |this, cx| {
287+
this.statuses
288+
.retain(|status| !checking_for_update.contains(&status.name));
289+
this.dismiss_error_message(&DismissErrorMessage, cx)
290+
})),
262291
});
263292
}
264293

@@ -271,7 +300,16 @@ impl ActivityIndicator {
271300
),
272301
message: format!(
273302
"Failed to download {}. Click to show error.",
274-
failed.join(", "),
303+
failed
304+
.iter()
305+
.map(|name| name.0.as_ref())
306+
.fold(String::new(), |mut acc, s| {
307+
if !acc.is_empty() {
308+
acc.push_str(", ");
309+
}
310+
acc.push_str(s);
311+
acc
312+
}),
275313
),
276314
on_click: Some(Arc::new(|this, cx| {
277315
this.show_error_message(&Default::default(), cx)
@@ -304,7 +342,9 @@ impl ActivityIndicator {
304342
.into_any_element(),
305343
),
306344
message: "Checking for Zed updates…".to_string(),
307-
on_click: None,
345+
on_click: Some(Arc::new(|this, cx| {
346+
this.dismiss_error_message(&DismissErrorMessage, cx)
347+
})),
308348
}),
309349
AutoUpdateStatus::Downloading => Some(Content {
310350
icon: Some(
@@ -313,7 +353,9 @@ impl ActivityIndicator {
313353
.into_any_element(),
314354
),
315355
message: "Downloading Zed update…".to_string(),
316-
on_click: None,
356+
on_click: Some(Arc::new(|this, cx| {
357+
this.dismiss_error_message(&DismissErrorMessage, cx)
358+
})),
317359
}),
318360
AutoUpdateStatus::Installing => Some(Content {
319361
icon: Some(
@@ -322,7 +364,9 @@ impl ActivityIndicator {
322364
.into_any_element(),
323365
),
324366
message: "Installing Zed update…".to_string(),
325-
on_click: None,
367+
on_click: Some(Arc::new(|this, cx| {
368+
this.dismiss_error_message(&DismissErrorMessage, cx)
369+
})),
326370
}),
327371
AutoUpdateStatus::Updated { binary_path } => Some(Content {
328372
icon: None,
@@ -342,7 +386,7 @@ impl ActivityIndicator {
342386
),
343387
message: "Auto update failed".to_string(),
344388
on_click: Some(Arc::new(|this, cx| {
345-
this.dismiss_error_message(&Default::default(), cx)
389+
this.dismiss_error_message(&DismissErrorMessage, cx)
346390
})),
347391
}),
348392
AutoUpdateStatus::Idle => None,
@@ -360,7 +404,9 @@ impl ActivityIndicator {
360404
.into_any_element(),
361405
),
362406
message: format!("Updating {extension_id} extension…"),
363-
on_click: None,
407+
on_click: Some(Arc::new(|this, cx| {
408+
this.dismiss_error_message(&DismissErrorMessage, cx)
409+
})),
364410
});
365411
}
366412
}

0 commit comments

Comments
 (0)