Struct tauri::api::notification::Notification
source · pub struct Notification { /* private fields */ }
Available on
desktop
and 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§
source§impl 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§
source§impl Debug for Notification
impl Debug for Notification
source§impl Default for Notification
impl Default for Notification
source§fn default() -> Notification
fn default() -> Notification
Returns the “default value” for a type. Read more