pub struct Notification<R: Runtime> { /* private fields */ }Expand description
Access to the notification APIs.
You can get an instance of this type via NotificationExt
Implementations§
Source§impl<R: Runtime> Notification<R>
impl<R: Runtime> Notification<R>
Sourcepub fn builder(&self) -> NotificationBuilder<R>
pub fn builder(&self) -> NotificationBuilder<R>
Creates a new builder for a notification.
§Examples
use tauri_plugin_notification::NotificationExt;
fn notify<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
app.notification()
.builder()
.title("Tauri")
.body("Tauri is awesome!")
.show()
.unwrap();
}Sourcepub fn request_permission(&self) -> Result<PermissionState>
pub fn request_permission(&self) -> Result<PermissionState>
Requests the permission to send notifications.
Desktop applications do not need to ask for this permission,
so this always resolves to PermissionState::Granted without prompting the user.
Sourcepub fn permission_state(&self) -> Result<PermissionState>
pub fn permission_state(&self) -> Result<PermissionState>
Checks whether the permission to send notifications was granted.
Desktop applications do not need to ask for this permission,
so this always resolves to PermissionState::Granted.
Sourcepub fn register_action_types(&self, types: Vec<ActionType>) -> Result<()>
pub fn register_action_types(&self, types: Vec<ActionType>) -> Result<()>
Registers the action types a notification can reference
through NotificationBuilder::action_type_id.
On desktop the actions of a type become the buttons of the notification; only their identifier and title are used. A type registered again replaces the previous one.
Sourcepub fn remove_active(&self, notifications: Vec<i32>) -> Result<()>
pub fn remove_active(&self, notifications: Vec<i32>) -> Result<()>
Removes the delivered notifications with the given identifiers.
§Platform-specific
- Linux and the BSDs: closes notifications shown while an action listener existed.
- macOS and Windows: does nothing,
notify-rustcannot remove a shown notification there.
Sourcepub fn remove_all_active(&self) -> Result<()>
pub fn remove_all_active(&self) -> Result<()>
Removes all delivered notifications that can still be closed.
Sourcepub fn on_action<F: Fn(&ActionPerformed) + Send + Sync + 'static>(
&self,
handler: F,
) -> Result<()>
pub fn on_action<F: Fn(&ActionPerformed) + Send + Sync + 'static>( &self, handler: F, ) -> Result<()>
Calls handler for every action the user performs on a notification of this app:
a click on the notification itself (tap) or on one of its actions.
Notifications shown before the first handler or listener existed report nothing. The handler runs on a background thread and should return quickly.
§Errors
Never on desktop; the signature matches the mobile one.