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.
This commit is contained in:
Hector Candelaria 2024-07-31 23:07:18 -04:00
parent 88af0e735d
commit f37f28cfff

View file

@ -229,7 +229,6 @@ impl From<NotificationDirection> for web_sys::NotificationDirection {
/// ///
/// The following implementations are missing: /// The following implementations are missing:
/// - `vibrate` /// - `vibrate`
/// - `image`
#[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 {
@ -263,6 +262,11 @@ pub struct UseWebNotificationOptions {
#[builder(into)] #[builder(into)]
icon: Option<String>, icon: Option<String>,
/// 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<String>,
/// A boolean value indicating that a notification should remain active until the /// A boolean value indicating that a notification should remain active until the
/// user clicks or dismisses it, rather than closing automatically. /// user clicks or dismisses it, rather than closing automatically.
require_interaction: bool, require_interaction: bool,
@ -300,6 +304,7 @@ impl Default for UseWebNotificationOptions {
language: None, language: None,
tag: None, tag: None,
icon: None, icon: None,
image: None,
require_interaction: false, require_interaction: false,
renotify: false, renotify: false,
silent: None, silent: None,
@ -329,6 +334,10 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions {
web_sys_options.icon(icon); web_sys_options.icon(icon);
} }
if let Some(image) = &options.image {
web_sys_options.image(image);
}
if let Some(language) = &options.language { if let Some(language) = &options.language {
web_sys_options.lang(language); web_sys_options.lang(language);
} }
@ -347,7 +356,6 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions {
/// ///
/// The following implementations are missing: /// The following implementations are missing:
/// - `vibrate` /// - `vibrate`
/// - `image`
#[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 {
@ -382,6 +390,11 @@ pub struct ShowOptions {
#[builder(into)] #[builder(into)]
icon: Option<String>, icon: Option<String>,
/// 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<String>,
/// A boolean value indicating that a notification should remain active until the /// A boolean value indicating that a notification should remain active until the
/// user clicks or dismisses it, rather than closing automatically. /// user clicks or dismisses it, rather than closing automatically.
#[builder(into)] #[builder(into)]
@ -417,6 +430,10 @@ impl ShowOptions {
options.icon(icon); options.icon(icon);
} }
if let Some(image) = &self.image {
options.image(image);
}
if let Some(language) = &self.language { if let Some(language) = &self.language {
options.lang(language); options.lang(language);
} }