Feat: Add silent field to UseWebNotificationOptions and ShowOptions

Introduced the `silent` field to the `UseWebNotificationOptions` and `ShowOptions` structures,
allowing notifications to be displayed in silent.
This commit is contained in:
Hector Candelaria 2024-07-31 22:18:58 -04:00
parent 0b6903fccc
commit 88af0e735d

View file

@ -229,7 +229,6 @@ impl From<NotificationDirection> 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<bool>,
/// Called when the user clicks on displayed `Notification`.
on_click: Rc<dyn Fn(web_sys::Event)>,
@ -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);
@ -341,7 +347,6 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions {
///
/// The following implementations are missing:
/// - `vibrate`
/// - `silent`
/// - `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<bool>,
/// 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<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<bool>,
}
#[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));
}
}
}