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
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
The none-equivalent value.