Feat: Add vibrate field to use_web_notification

- Implemented `vibrate` option in `UseWebNotificationOptions` and
  `ShowOptions` structures allowing specifying vibration patterns for
  notifications.
This commit is contained in:
Hector Candelaria 2024-08-21 21:25:24 -04:00
parent 480b1fa4ee
commit 9cb0e386aa

View file

@ -228,7 +228,6 @@ impl From<NotificationDirection> for web_sys::NotificationDirection {
/// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info.
/// ///
/// The following implementations are missing: /// The following implementations are missing:
/// - `vibrate`
#[derive(DefaultBuilder, Clone)] #[derive(DefaultBuilder, Clone)]
#[cfg_attr(feature = "ssr", allow(dead_code))] #[cfg_attr(feature = "ssr", allow(dead_code))]
pub struct UseWebNotificationOptions { pub struct UseWebNotificationOptions {
@ -281,6 +280,10 @@ pub struct UseWebNotificationOptions {
#[builder(into)] #[builder(into)]
silent: Option<bool>, silent: Option<bool>,
/// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating.
#[builder(into)]
vibrate: Option<wasm_bindgen::JsValue>,
/// Called when the user clicks on displayed `Notification`. /// Called when the user clicks on displayed `Notification`.
on_click: Rc<dyn Fn(web_sys::Event)>, on_click: Rc<dyn Fn(web_sys::Event)>,
@ -308,6 +311,7 @@ impl Default for UseWebNotificationOptions {
require_interaction: false, require_interaction: false,
renotify: false, renotify: false,
silent: None, silent: None,
vibrate: None,
on_click: Rc::new(|_| {}), on_click: Rc::new(|_| {}),
on_close: Rc::new(|_| {}), on_close: Rc::new(|_| {}),
on_error: Rc::new(|_| {}), on_error: Rc::new(|_| {}),
@ -345,6 +349,9 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions {
web_sys_options.set_tag(tag); web_sys_options.set_tag(tag);
} }
if let Some(vibrate) = &options.vibrate {
web_sys_options.set_vibrate(vibrate);
}
web_sys_options web_sys_options
} }
} }
@ -354,7 +361,6 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions {
/// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info.
/// ///
/// The following implementations are missing: /// The following implementations are missing:
/// - `vibrate`
#[derive(DefaultBuilder, Default)] #[derive(DefaultBuilder, Default)]
#[cfg_attr(feature = "ssr", allow(dead_code))] #[cfg_attr(feature = "ssr", allow(dead_code))]
pub struct ShowOptions { pub struct ShowOptions {
@ -408,6 +414,10 @@ pub struct ShowOptions {
/// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent.
#[builder(into)] #[builder(into)]
silent: Option<bool>, silent: Option<bool>,
/// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating.
#[builder(into)]
vibrate: Option<wasm_bindgen::JsValue>,
} }
#[cfg(not(feature = "ssr"))] #[cfg(not(feature = "ssr"))]
@ -448,6 +458,10 @@ impl ShowOptions {
if let Some(silent) = self.silent { if let Some(silent) = self.silent {
options.set_silent(Some(silent)); options.set_silent(Some(silent));
} }
if let Some(vibrate) = &self.vibrate {
options.set_vibrate(vibrate);
}
} }
} }