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§

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(())
  }

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(())
  }

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(())
  }

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(())
  }

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 use Self::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()
    }
  }
Available on crate feature 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§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more