Add button to close notification
This commit is contained in:
parent
e0d1224173
commit
a82c0a5577
4 changed files with 67 additions and 15 deletions
|
|
@ -297,6 +297,8 @@ impl Notifications {
|
|||
}
|
||||
|
||||
fn close_notification(&self, id: NotificationId, reason: CloseReason) {
|
||||
self.inner().notifications.borrow_mut().remove(&id);
|
||||
|
||||
self.emit_by_name("notification-closed", &[&id]).unwrap();
|
||||
|
||||
if let Some(connection) = self.inner().connection.borrow().as_ref() {
|
||||
|
|
@ -312,6 +314,10 @@ impl Notifications {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn dismiss(&self, id: NotificationId) {
|
||||
self.close_notification(id, CloseReason::Dismiss);
|
||||
}
|
||||
|
||||
fn bus_acquired(&self, connection: gio::DBusConnection, _name: &str) {
|
||||
*self.inner().connection.borrow_mut() = Some(connection);
|
||||
}
|
||||
|
|
@ -396,4 +402,16 @@ impl Notifications {
|
|||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn connect_notification_closed<F: Fn(NotificationId) + 'static>(
|
||||
&self,
|
||||
cb: F,
|
||||
) -> SignalHandlerId {
|
||||
self.connect_local("notification-closed", false, move |values| {
|
||||
let id = values[1].get().unwrap();
|
||||
cb(id);
|
||||
None
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue