From 9cb0e386aabfb28f65d4b5254179d8ca337d3703 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 21 Aug 2024 21:25:24 -0400 Subject: [PATCH] Feat: Add `vibrate` field to `use_web_notification` - Implemented `vibrate` option in `UseWebNotificationOptions` and `ShowOptions` structures allowing specifying vibration patterns for notifications. --- src/use_web_notification.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 2a51626..d8dbd38 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -228,7 +228,6 @@ impl From for web_sys::NotificationDirection { /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// /// The following implementations are missing: -/// - `vibrate` #[derive(DefaultBuilder, Clone)] #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct UseWebNotificationOptions { @@ -281,6 +280,10 @@ pub struct UseWebNotificationOptions { #[builder(into)] silent: Option, + /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. + #[builder(into)] + vibrate: Option, + /// Called when the user clicks on displayed `Notification`. on_click: Rc, @@ -308,6 +311,7 @@ impl Default for UseWebNotificationOptions { require_interaction: false, renotify: false, silent: None, + vibrate: None, on_click: Rc::new(|_| {}), on_close: Rc::new(|_| {}), on_error: Rc::new(|_| {}), @@ -345,6 +349,9 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { web_sys_options.set_tag(tag); } + if let Some(vibrate) = &options.vibrate { + web_sys_options.set_vibrate(vibrate); + } 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. /// /// The following implementations are missing: -/// - `vibrate` #[derive(DefaultBuilder, Default)] #[cfg_attr(feature = "ssr", allow(dead_code))] 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. #[builder(into)] silent: Option, + + /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. + #[builder(into)] + vibrate: Option, } #[cfg(not(feature = "ssr"))] @@ -448,6 +458,10 @@ impl ShowOptions { if let Some(silent) = self.silent { options.set_silent(Some(silent)); } + + if let Some(vibrate) = &self.vibrate { + options.set_vibrate(vibrate); + } } }