pub struct NotificationService { /* private fields */ }Expand description
A notification daemon that follows XDG Desktop Notifications Specification.
NotificationService implements Clone and can be cloned cheapely since underlying data is
shared.
Implementations§
Source§impl NotificationService
impl NotificationService
Sourcepub fn new(cache_dir: Option<PathBuf>) -> Result<Self>
pub fn new(cache_dir: Option<PathBuf>) -> Result<Self>
Creates a new instance of the service loading the notification history from file.
cache_dir- Overrides the default cache directory located at~/.cache/ignis_notifications.
§Errors
Returns Error::IOError if loading notification history from file
fails.
Sourcepub fn new_in_memory() -> Self
pub fn new_in_memory() -> Self
Creates a new instance of the service without any I/O operations.
It doesn’t load the notification history from file and doesn’t save it consequently. This method can not fail and is guaranteed to return the instance.
Sourcepub fn settings(&self) -> Settings
pub fn settings(&self) -> Settings
Returns an instance of settings that affect behavior of the service.
Sourcepub async fn run(&self) -> Result<()>
pub async fn run(&self) -> Result<()>
Runs the service.
You have to call this this method in order to receive notifications and perform operations on them, such as dismissing or invoking actions. It creates D-Bus connection and registers D-Bus interface on the session bus. Must be called only once.
§Errors
Returns Error::DBusError, for example, if the name is already taken on the bus.
Returns Error::ConnectionInitializedTwice if this function is called
more than once.
Sourcepub async fn dismiss_notification(&self, id: u32) -> Result<()>
pub async fn dismiss_notification(&self, id: u32) -> Result<()>
Dismiss a notification by its ID.
The notification is removed from the history and application that sent the notification is notified through D-Bus.
Emits [Event::NotificationClosed] event.
§Errors
Returns Error::DBusError.
Returns Error::NotificationNotFound if the notification with such ID is
not found.
Sourcepub async fn invoke_action(
&self,
notification_id: u32,
action_key: &str,
) -> Result<()>
pub async fn invoke_action( &self, notification_id: u32, action_key: &str, ) -> Result<()>
Invokes an action by its action key and notification ID it belongs to.
§Errors
Returns Error::DBusError.
Sourcepub fn get_notifications(&self) -> Vec<NotificationHandle>
pub fn get_notifications(&self) -> Vec<NotificationHandle>
Returns a vector of notification handles.
Sourcepub fn get_notification_by_id(&self, id: u32) -> Option<NotificationHandle>
pub fn get_notification_by_id(&self, id: u32) -> Option<NotificationHandle>
Returns a notification handle by notification ID.
Sourcepub async fn clear_notifications(&self) -> Result<()>
pub async fn clear_notifications(&self) -> Result<()>
Clears the notification history.
It dismisses each notification and notifies applications.
§Warning
It does NOT emit [Event::NotificationClosed] event for each notification.
Sourcepub fn on_notified<F>(&self, callback: F) -> usize
pub fn on_notified<F>(&self, callback: F) -> usize
Invokes a callback when a new notification is received.
The following arguments are passed to the callback:
- id - The ID of the notification
- handle - Notification handle
- replace - Whether this notification replaces the old one with the same ID
Sourcepub fn on_notification_closed<F>(&self, callback: F) -> usize
pub fn on_notification_closed<F>(&self, callback: F) -> usize
Invokes a callback when a notification is closed.
The following arguments are passed to the callback:
- id - The ID of the notification
- reason - The reason why the notification was closed
Sourcepub fn on_notify_notifications<F>(&self, callback: F) -> usize
pub fn on_notify_notifications<F>(&self, callback: F) -> usize
Invokes a callback when value of [get_notifications] changes.
It includes arriving of new notifications, closing and clearing notifications.
Trait Implementations§
Source§impl Clone for NotificationService
impl Clone for NotificationService
Source§fn clone(&self) -> NotificationService
fn clone(&self) -> NotificationService
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more