From 54a04ac382d361cb9bf2f1426882f2ec419ba6df Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Fri, 23 Aug 2024 23:39:42 -0400 Subject: [PATCH] Docs: Update vibration pattern documentation and convert helper function - Updated comment for `vibrate` to describe the `Vec` format for vibration patterns. - Modified `vibration_pattern_to_jsvalue` to accept a slice (`&[u16]`) and convert it to a `JsValue` array. --- src/use_web_notification.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index fd730d6..23f5f83 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -281,7 +281,8 @@ pub struct UseWebNotificationOptions { #[builder(into)] silent: Option, - /// A `Vec` value specifying the vibration pattern in which the device is vibrating and not vibrating. + /// A `Vec` specifying the vibration pattern in milliseconds for vibrating and not vibrating. + /// The last entry can be a vibration since it stops automatically after each period. #[builder(into)] vibrate: Option>, @@ -416,7 +417,8 @@ pub struct ShowOptions { #[builder(into)] silent: Option, - /// A `Vec` value specifying the vibration pattern in which the device is vibrating and not vibrating. + /// A `Vec` specifying the vibration pattern in milliseconds for vibrating and not vibrating. + /// The last entry can be a vibration since it stops automatically after each period. #[builder(into)] vibrate: Option>, } @@ -477,8 +479,8 @@ fn browser_supports_notifications() -> bool { false } -/// Helper function to convert `Vec` into a `JsValue` array that represents a vibration pattern -fn vibration_pattern_to_jsvalue(pattern: &Vec) -> JsValue { +/// Helper function to convert a slice of `u16` into a `JsValue` array that represents a vibration pattern +fn vibration_pattern_to_jsvalue(pattern: &[u16]) -> JsValue { let array = js_sys::Array::new(); for &value in pattern.iter() { array.push(&JsValue::from(value));