mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-22 16:49:22 -05:00
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:
parent
0b6903fccc
commit
88af0e735d
1 changed files with 19 additions and 4 deletions
|
@ -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);
|
||||
|
@ -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<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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue