diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 8870a89..986fcc8 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -229,7 +229,6 @@ impl From for web_sys::NotificationDirection { /// /// The following implementations are missing: /// - `vibrate` -/// - `silent` /// - `image` #[derive(DefaultBuilder, Clone)] #[cfg_attr(feature = "ssr", allow(dead_code))] @@ -273,6 +272,11 @@ pub struct UseWebNotificationOptions { #[builder(into)] renotify: bool, + /// A boolean value specifying whether the notification should be silent, regardless of the device settings. + /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. + #[builder(into)] + silent: Option, + /// Called when the user clicks on displayed `Notification`. on_click: Rc, @@ -298,6 +302,7 @@ impl Default for UseWebNotificationOptions { icon: None, require_interaction: false, renotify: false, + silent: None, on_click: Rc::new(|_| {}), on_close: Rc::new(|_| {}), on_error: Rc::new(|_| {}), @@ -313,7 +318,8 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { web_sys_options .dir(options.direction.into()) .require_interaction(options.require_interaction) - .renotify(options.renotify); + .renotify(options.renotify) + .silent(options.silent); if let Some(body) = &options.body { web_sys_options.body(body); @@ -340,8 +346,7 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// /// The following implementations are missing: -/// - `vibrate` -/// - `silent` +/// - `vibrate` /// - `image` #[derive(DefaultBuilder, Default)] #[cfg_attr(feature = "ssr", allow(dead_code))] @@ -381,10 +386,16 @@ pub struct ShowOptions { /// user clicks or dismisses it, rather than closing automatically. #[builder(into)] require_interaction: Option, + /// A boolean value specifying whether the user should be notified after a new notification replaces an old one. /// The default is `false`, which means they won't be notified. If `true`, then `tag` also must be set. #[builder(into)] renotify: Option, + + /// A boolean value specifying whether the notification should be silent, regardless of the device settings. + /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. + #[builder(into)] + silent: Option, } #[cfg(not(feature = "ssr"))] @@ -417,6 +428,10 @@ impl ShowOptions { if let Some(renotify) = self.renotify { options.renotify(renotify); } + + if let Some(silent) = self.silent { + options.silent(Some(silent)); + } } }