Struct tauri::api::notification::Notification
source · [−]pub struct Notification { /* private fields */ }
Available on crate feature
notification
only.Expand description
The desktop notification definition.
Allows you to construct a Notification data and send it.
Examples
use tauri::api::notification::Notification;
// first we build the application to access the Tauri configuration
let app = tauri::Builder::default()
// on an actual app, remove the string argument
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("error while building tauri application");
// shows a notification with the given title and body
Notification::new(&app.config().tauri.bundle.identifier)
.title("New message")
.body("You've got a new message.")
.show();
// run the app
app.run(|_app_handle, _event| {});
Implementations
sourceimpl Notification
impl Notification
sourcepub fn show(self) -> Result<()>
pub fn show(self) -> Result<()>
Shows the notification.
Examples
use tauri::api::notification::Notification;
// on an actual app, remove the string argument
let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
Notification::new(&context.config().tauri.bundle.identifier)
.title("Tauri")
.body("Tauri is awesome!")
.show()
.unwrap();
Platform-specific
- Windows: Not supported on Windows 7. If your app targets it, enable the
windows7-compat
feature and useSelf::notify
.
sourcepub fn notify<R: Runtime>(self, app: &AppHandle<R>) -> Result<()>
Available on crate feature windows7-compat
only.
pub fn notify<R: Runtime>(self, app: &AppHandle<R>) -> Result<()>
windows7-compat
only.Shows the notification. This API is similar to Self::show
, but it also works on Windows 7.
Examples
use tauri::api::notification::Notification;
// on an actual app, remove the string argument
let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
let identifier = context.config().tauri.bundle.identifier.clone();
tauri::Builder::default()
.setup(move |app| {
Notification::new(&identifier)
.title("Tauri")
.body("Tauri is awesome!")
.notify(&app.handle())
.unwrap();
Ok(())
})
.run(context)
.expect("error while running tauri application");
Trait Implementations
sourceimpl Debug for Notification
impl Debug for Notification
sourceimpl Default for Notification
impl Default for Notification
sourcefn default() -> Notification
fn default() -> Notification
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for Notification
impl Send for Notification
impl Sync for Notification
impl Unpin for Notification
impl UnwindSafe for Notification
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more