notifications: initial logic for sending action signal

This commit is contained in:
Ian Douglas Scott 2021-09-23 14:42:24 -07:00
parent 94def67e85
commit 13aa62cef8
3 changed files with 31 additions and 4 deletions

View file

@ -207,6 +207,12 @@ impl From<NotificationId> for u32 {
}
}
impl ToVariant for NotificationId {
fn to_variant(&self) -> glib::Variant {
self.0.get().to_variant()
}
}
impl NotificationId {
fn new(value: u32) -> Option<Self> {
NonZeroU32::new(value).map(Self)
@ -308,7 +314,7 @@ impl Notifications {
PATH,
INTERFACE,
"CloseNotification",
Some(&(&(reason as u32),).to_variant()),
Some(&(id, &(reason as u32)).to_variant()),
)
.unwrap();
}
@ -318,6 +324,20 @@ impl Notifications {
self.close_notification(id, CloseReason::Dismiss);
}
pub fn invoke_action(&self, id: NotificationId, action_key: &str) {
if let Some(connection) = self.inner().connection.borrow().as_ref() {
connection
.emit_signal(
None,
PATH,
INTERFACE,
"ActionInvoked",
Some(&(&(id, action_key),).to_variant()),
)
.unwrap();
}
}
fn bus_acquired(&self, connection: gio::DBusConnection, _name: &str) {
*self.inner().connection.borrow_mut() = Some(connection);
}