notification: Fix when multiple notifications pop up at the same time, autohide not work (#255)
This commit is contained in:
parent
20926b7077
commit
f20f573dbc
1 changed files with 7 additions and 15 deletions
|
|
@ -135,7 +135,7 @@ impl Notification {
|
|||
|
||||
/// Set the title of the notification, default is None.
|
||||
///
|
||||
/// If tilte is None, the notification will not have a title.
|
||||
/// If title is None, the notification will not have a title.
|
||||
pub fn title(mut self, title: impl Into<SharedString>) -> Self {
|
||||
self.title = Some(title.into());
|
||||
self
|
||||
|
|
@ -305,23 +305,15 @@ impl NotificationList {
|
|||
})
|
||||
.detach();
|
||||
|
||||
self.notifications.push_back(notification);
|
||||
self.notifications.push_back(notification.clone());
|
||||
if autohide {
|
||||
// Sleep for 5 seconds to autohide the notification
|
||||
cx.spawn(|view, mut cx| async move {
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
Timer::after(Duration::from_secs(5)).await;
|
||||
let _ = view.update(&mut cx, |view, cx| {
|
||||
if let Some(ix) = view
|
||||
.notifications
|
||||
.iter()
|
||||
.position(|note| note.read(cx).autohide)
|
||||
{
|
||||
if let Some(note) = view.notifications.get(ix) {
|
||||
note.update(cx, |note, cx| note.dismiss(&ClickEvent::default(), cx));
|
||||
}
|
||||
}
|
||||
cx.notify()
|
||||
});
|
||||
|
||||
notification
|
||||
.update(&mut cx, |note, cx| note.dismiss(&ClickEvent::default(), cx))
|
||||
.expect("failed to auto hide notification");
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue