Skip to main content

NotificationService

Struct NotificationService 

Source
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

Source

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.

Source

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.

Source

pub fn settings(&self) -> Settings

Returns an instance of settings that affect behavior of the service.

Source

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.

Source

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.

Source

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.

Source

pub fn get_notifications(&self) -> Vec<NotificationHandle>

Returns a vector of notification handles.

Source

pub fn get_notification_by_id(&self, id: u32) -> Option<NotificationHandle>

Returns a notification handle by notification ID.

Source

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.

Source

pub fn on_notified<F>(&self, callback: F) -> usize
where F: Fn(&(u32, NotificationHandle, bool)) + Send + Sync + 'static,

Invokes a callback when a new notification is received.

The following arguments are passed to the callback:

  1. id - The ID of the notification
  2. handle - Notification handle
  3. replace - Whether this notification replaces the old one with the same ID
Source

pub fn on_notification_closed<F>(&self, callback: F) -> usize
where F: Fn(&(u32, CloseReason)) + Send + Sync + 'static,

Invokes a callback when a notification is closed.

The following arguments are passed to the callback:

  1. id - The ID of the notification
  2. reason - The reason why the notification was closed
Source

pub fn on_notify_notifications<F>(&self, callback: F) -> usize
where F: Fn() + Send + Sync + 'static,

Invokes a callback when value of [get_notifications] changes.

It includes arriving of new notifications, closing and clearing notifications.

Source

pub fn on_notifications_cleared<F>(&self, callback: F) -> usize
where F: Fn() + Send + Sync + 'static,

Invokes a callback when notifications are cleared by a call to [clear_notifications].

Trait Implementations§

Source§

impl Clone for NotificationService

Source§

fn clone(&self) -> NotificationService

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more