Skip to main content

NotificationBuilder

Struct NotificationBuilder 

Source
pub struct NotificationBuilder<R: Runtime> { /* private fields */ }
Expand description

The notification builder.

Implementations§

Source§

impl<R: Runtime> NotificationBuilder<R>

Source

pub fn show(self) -> Result<()>

Shows the notification.

When no title was set with Self::title, the productName from the Tauri configuration is used instead. Only the title, body, icon, sound and the actions of the action type of the notification are used on desktop; the scheduling and grouping options are ignored.

When a handler is registered with Notification::on_action or a JavaScript onAction listener exists, a click on the notification (tap) or on one of its actions is reported to them, as far as the notification server reports it. Otherwise the actions of the notification are not shown, since nothing would receive them.

§Platform-specific
  • Windows: a click is only reported while the toast is on screen, not once it moved to the Action Center.
  • macOS: two or more actions are shown in an “Options” menu, and a click on the menu button itself reports the first action. Actions are told apart by their title.

The notification is dispatched on a background task, so this returns as soon as the payload is prepared.

§Errors

Returns an error when the notification could not be prepared, e.g. when the path of the running executable cannot be resolved on Windows.

Source§

impl<R: Runtime> NotificationBuilder<R>

Source

pub fn id(self, id: i32) -> Self

Sets the notification identifier.

Source

pub fn channel_id(self, id: impl Into<String>) -> Self

Sets the identifier of the notification channel that delivers this notification.

If the channel does not exist, the notification won’t fire. Make sure the channel exists with Notification::list_channels and Notification::create_channel.

Only used on Android.

Source

pub fn title(self, title: impl Into<String>) -> Self

Sets the notification title.

Source

pub fn body(self, body: impl Into<String>) -> Self

Sets the notification body.

Source

pub fn schedule(self, schedule: Schedule) -> Self

Schedule this notification to fire on a later time or a fixed interval.

Source

pub fn large_body(self, large_body: impl Into<String>) -> Self

Multiline text. Changes the notification style to big text. Cannot be used with inboxLines.

Source

pub fn summary(self, summary: impl Into<String>) -> Self

Detail text for the notification with largeBody, inboxLines or groupSummary.

Source

pub fn action_type_id(self, action_type_id: impl Into<String>) -> Self

Defines an action type for this notification.

Source

pub fn group(self, group: impl Into<String>) -> Self

Source

pub fn group_summary(self) -> Self

Instructs the system that this notification is the summary of a group on Android.

Source

pub fn sound(self, sound: impl Into<String>) -> Self

The sound resource name for the notification.

Source

pub fn inbox_line(self, line: impl Into<String>) -> Self

Append an inbox line to the notification. Changes the notification style to inbox. Cannot be used with largeBody.

Only supports up to 5 lines.

Source

pub fn icon(self, icon: impl Into<String>) -> Self

Notification icon.

On Android the icon must be placed in the app’s res/drawable folder.

Source

pub fn large_icon(self, large_icon: impl Into<String>) -> Self

Notification large icon (Android).

The icon must be placed in the app’s res/drawable folder.

Source

pub fn icon_color(self, icon_color: impl Into<String>) -> Self

Icon color on Android.

Source

pub fn attachment(self, attachment: Attachment) -> Self

Append an attachment to the notification.

Source

pub fn extra(self, key: impl Into<String>, value: impl Serialize) -> Self

Adds an extra payload to store in the notification.

Source

pub fn ongoing(self) -> Self

If true, the notification cannot be dismissed by the user on Android.

An application service must manage the dismissal of the notification. It is typically used to indicate a background task that is pending (e.g. a file download) or the user is engaged with (e.g. playing music).

Source

pub fn auto_cancel(self) -> Self

Automatically cancel the notification when the user clicks on it.

Source

pub fn silent(self) -> Self

Changes the notification presentation to be silent on iOS (no badge, no sound, not listed).

Trait Implementations§

Source§

impl<R: Debug + Runtime> Debug for NotificationBuilder<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> MaybeSendSync for T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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