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 new(identifier: impl Into<String>) -> Self
pub fn new(identifier: impl Into<String>) -> Self
Initializes a instance of a Notification.
Examples found in repository?
src/endpoints/notification.rs (line 52)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn notification<R: Runtime>(
context: InvokeContext<R>,
options: NotificationOptions,
) -> super::Result<()> {
let mut notification =
Notification::new(context.config.tauri.bundle.identifier.clone()).title(options.title);
if let Some(body) = options.body {
notification = notification.body(body);
}
if let Some(icon) = options.icon {
notification = notification.icon(icon);
}
#[cfg(feature = "windows7-compat")]
{
notification.notify(&context.window.app_handle)?;
}
#[cfg(not(feature = "windows7-compat"))]
notification.show()?;
Ok(())
}
sourcepub fn body(self, body: impl Into<String>) -> Self
pub fn body(self, body: impl Into<String>) -> Self
Sets the notification body.
Examples found in repository?
src/endpoints/notification.rs (line 54)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn notification<R: Runtime>(
context: InvokeContext<R>,
options: NotificationOptions,
) -> super::Result<()> {
let mut notification =
Notification::new(context.config.tauri.bundle.identifier.clone()).title(options.title);
if let Some(body) = options.body {
notification = notification.body(body);
}
if let Some(icon) = options.icon {
notification = notification.icon(icon);
}
#[cfg(feature = "windows7-compat")]
{
notification.notify(&context.window.app_handle)?;
}
#[cfg(not(feature = "windows7-compat"))]
notification.show()?;
Ok(())
}
sourcepub fn title(self, title: impl Into<String>) -> Self
pub fn title(self, title: impl Into<String>) -> Self
Sets the notification title.
Examples found in repository?
src/endpoints/notification.rs (line 52)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn notification<R: Runtime>(
context: InvokeContext<R>,
options: NotificationOptions,
) -> super::Result<()> {
let mut notification =
Notification::new(context.config.tauri.bundle.identifier.clone()).title(options.title);
if let Some(body) = options.body {
notification = notification.body(body);
}
if let Some(icon) = options.icon {
notification = notification.icon(icon);
}
#[cfg(feature = "windows7-compat")]
{
notification.notify(&context.window.app_handle)?;
}
#[cfg(not(feature = "windows7-compat"))]
notification.show()?;
Ok(())
}
sourcepub fn icon(self, icon: impl Into<String>) -> Self
pub fn icon(self, icon: impl Into<String>) -> Self
Sets the notification icon.
Examples found in repository?
src/endpoints/notification.rs (line 57)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn notification<R: Runtime>(
context: InvokeContext<R>,
options: NotificationOptions,
) -> super::Result<()> {
let mut notification =
Notification::new(context.config.tauri.bundle.identifier.clone()).title(options.title);
if let Some(body) = options.body {
notification = notification.body(body);
}
if let Some(icon) = options.icon {
notification = notification.icon(icon);
}
#[cfg(feature = "windows7-compat")]
{
notification.notify(&context.window.app_handle)?;
}
#[cfg(not(feature = "windows7-compat"))]
notification.show()?;
Ok(())
}
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
.
Examples found in repository?
src/api/notification.rs (line 178)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
pub fn notify<R: crate::Runtime>(self, app: &crate::AppHandle<R>) -> crate::api::Result<()> {
#[cfg(windows)]
{
if crate::utils::platform::is_windows_7() {
self.notify_win7(app)
} else {
#[allow(deprecated)]
self.show()
}
}
#[cfg(not(windows))]
{
#[allow(deprecated)]
self.show()
}
}
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");
Examples found in repository?
src/endpoints/notification.rs (line 61)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn notification<R: Runtime>(
context: InvokeContext<R>,
options: NotificationOptions,
) -> super::Result<()> {
let mut notification =
Notification::new(context.config.tauri.bundle.identifier.clone()).title(options.title);
if let Some(body) = options.body {
notification = notification.body(body);
}
if let Some(icon) = options.icon {
notification = notification.icon(icon);
}
#[cfg(feature = "windows7-compat")]
{
notification.notify(&context.window.app_handle)?;
}
#[cfg(not(feature = "windows7-compat"))]
notification.show()?;
Ok(())
}
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