From f37f28cfff3f6de50e36d72b4fcc9682b2ed3e90 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 31 Jul 2024 23:07:18 -0400 Subject: [PATCH] Feat: Add `image` field to `UseWebNotificationOptions` and `ShowOptions` Added the `image` field to the `UseWebNotificationOptions` and `ShowOptions` structures. This field allows specifying an image URL to be displayed in the notification. --- src/use_web_notification.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 986fcc8..a919052 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -229,7 +229,6 @@ impl From for web_sys::NotificationDirection { /// /// The following implementations are missing: /// - `vibrate` -/// - `image` #[derive(DefaultBuilder, Clone)] #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct UseWebNotificationOptions { @@ -263,6 +262,11 @@ pub struct UseWebNotificationOptions { #[builder(into)] icon: Option, + /// The URL of the image to be displayed as part of the notification as specified + /// in the constructor's options parameter. + #[builder(into)] + image: Option, + /// A boolean value indicating that a notification should remain active until the /// user clicks or dismisses it, rather than closing automatically. require_interaction: bool, @@ -300,6 +304,7 @@ impl Default for UseWebNotificationOptions { language: None, tag: None, icon: None, + image: None, require_interaction: false, renotify: false, silent: None, @@ -329,6 +334,10 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { web_sys_options.icon(icon); } + if let Some(image) = &options.image { + web_sys_options.image(image); + } + if let Some(language) = &options.language { web_sys_options.lang(language); } @@ -347,7 +356,6 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { /// /// The following implementations are missing: /// - `vibrate` -/// - `image` #[derive(DefaultBuilder, Default)] #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct ShowOptions { @@ -382,6 +390,11 @@ pub struct ShowOptions { #[builder(into)] icon: Option, + /// The URL of the image to be displayed as part of the notification as specified + /// in the constructor's options parameter. + #[builder(into)] + image: Option, + /// A boolean value indicating that a notification should remain active until the /// user clicks or dismisses it, rather than closing automatically. #[builder(into)] @@ -417,6 +430,10 @@ impl ShowOptions { options.icon(icon); } + if let Some(image) = &self.image { + options.image(image); + } + if let Some(language) = &self.language { options.lang(language); }