From ff6519275b53c8b4b0a981ea144a929f45671421 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Mon, 23 Oct 2023 23:39:54 -0500 Subject: [PATCH 1/8] Updated Notification APIs --- .../src/features/gen_NotificationAction.rs | 65 ++++++++++++++++ .../src/features/gen_NotificationOptions.rs | 74 +++++++++++++++++++ crates/web-sys/src/features/mod.rs | 6 ++ .../webidls/enabled/Notification.webidl | 13 +++- 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 crates/web-sys/src/features/gen_NotificationAction.rs diff --git a/crates/web-sys/src/features/gen_NotificationAction.rs b/crates/web-sys/src/features/gen_NotificationAction.rs new file mode 100644 index 00000000000..919e13c0f37 --- /dev/null +++ b/crates/web-sys/src/features/gen_NotificationAction.rs @@ -0,0 +1,65 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = NotificationAction)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `NotificationAction` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationAction`*"] + pub type NotificationAction; +} +impl NotificationAction { + #[doc = "Construct a new `NotificationAction`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationAction`*"] + pub fn new(action: &str, title: &str) -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret.action(action); + ret.title(title); + ret + } + #[doc = "Change the `action` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationAction`*"] + pub fn action(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = + ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("action"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `icon` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationAction`*"] + pub fn icon(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("icon"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `title` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationAction`*"] + pub fn title(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("title"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/gen_NotificationOptions.rs b/crates/web-sys/src/features/gen_NotificationOptions.rs index 31d504db744..5c15dd56bcb 100644 --- a/crates/web-sys/src/features/gen_NotificationOptions.rs +++ b/crates/web-sys/src/features/gen_NotificationOptions.rs @@ -20,6 +20,36 @@ impl NotificationOptions { let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); ret } + #[doc = "Change the `actions` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] + pub fn actions(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("actions"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `badge` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] + pub fn badge(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("badge"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } #[doc = "Change the `body` field of this object."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] @@ -73,6 +103,19 @@ impl NotificationOptions { let _ = r; self } + #[doc = "Change the `image` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] + pub fn image(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("image"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } #[doc = "Change the `lang` field of this object."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] @@ -86,6 +129,23 @@ impl NotificationOptions { let _ = r; self } + #[doc = "Change the `renotify` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] + pub fn renotify(&mut self, val: bool) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("renotify"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } #[doc = "Change the `requireInteraction` field of this object."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] @@ -103,6 +163,20 @@ impl NotificationOptions { let _ = r; self } + #[doc = "Change the `silent` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] + pub fn silent(&mut self, val: Option) -> &mut Self { + use wasm_bindgen::JsValue; + let r = + ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("silent"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } #[doc = "Change the `tag` field of this object."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 9a3bb1d99c1..9d3be3f2b42 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -5092,6 +5092,12 @@ mod gen_Notification; #[cfg(feature = "Notification")] pub use gen_Notification::*; +#[cfg(feature = "NotificationAction")] +#[allow(non_snake_case)] +mod gen_NotificationAction; +#[cfg(feature = "NotificationAction")] +pub use gen_NotificationAction::*; + #[cfg(feature = "NotificationBehavior")] #[allow(non_snake_case)] mod gen_NotificationBehavior; diff --git a/crates/web-sys/webidls/enabled/Notification.webidl b/crates/web-sys/webidls/enabled/Notification.webidl index 7d63d9732b3..19729174cb5 100644 --- a/crates/web-sys/webidls/enabled/Notification.webidl +++ b/crates/web-sys/webidls/enabled/Notification.webidl @@ -64,9 +64,14 @@ dictionary NotificationOptions { DOMString lang = ""; DOMString body = ""; DOMString tag = ""; - DOMString icon = ""; + USVString image; + USVString icon; + USVString badge; + boolean renotify = false; + boolean? silent = null; boolean requireInteraction = false; any data = null; + sequence actions = []; }; dictionary GetNotificationOptions { @@ -87,6 +92,12 @@ enum NotificationPermission { "granted" }; +dictionary NotificationAction { + required DOMString action; + required DOMString title; + USVString icon; +}; + callback NotificationPermissionCallback = undefined (NotificationPermission permission); enum NotificationDirection { From b3e71f03864350eedbb2bbc888e718aab4e60503 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Tue, 24 Oct 2023 15:40:45 -0500 Subject: [PATCH 2/8] Updated Notification APIs --- crates/web-sys/Cargo.toml | 3 +- .../features/gen_GetNotificationOptions.rs | 41 ------- .../web-sys/src/features/gen_Notification.rs | 91 ++++++++++---- .../src/features/gen_NotificationBehavior.rs | 113 ------------------ .../src/features/gen_NotificationOptions.rs | 17 +++ .../features/gen_ServiceWorkerRegistration.rs | 11 -- crates/web-sys/src/features/mod.rs | 12 -- .../webidls/enabled/Notification.webidl | 89 ++++---------- 8 files changed, 109 insertions(+), 268 deletions(-) delete mode 100644 crates/web-sys/src/features/gen_GetNotificationOptions.rs delete mode 100644 crates/web-sys/src/features/gen_NotificationBehavior.rs diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index 2163a277c6e..74d20795d79 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -444,7 +444,6 @@ GamepadPose = [] GamepadServiceTest = [] Geolocation = [] GetAnimationsOptions = [] -GetNotificationOptions = [] GetRootNodeOptions = [] GetUserMediaRequest = [] Gpu = [] @@ -880,7 +879,7 @@ NodeFilter = [] NodeIterator = [] NodeList = [] Notification = ["EventTarget"] -NotificationBehavior = [] +NotificationAction = [] NotificationDirection = [] NotificationEvent = ["Event", "ExtendableEvent"] NotificationEventInit = [] diff --git a/crates/web-sys/src/features/gen_GetNotificationOptions.rs b/crates/web-sys/src/features/gen_GetNotificationOptions.rs deleted file mode 100644 index ac6589dd67a..00000000000 --- a/crates/web-sys/src/features/gen_GetNotificationOptions.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![allow(unused_imports)] -#![allow(clippy::all)] -use super::*; -use wasm_bindgen::prelude::*; -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = :: js_sys :: Object , js_name = GetNotificationOptions)] - #[derive(Debug, Clone, PartialEq, Eq)] - #[doc = "The `GetNotificationOptions` dictionary."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `GetNotificationOptions`*"] - pub type GetNotificationOptions; -} -impl GetNotificationOptions { - #[doc = "Construct a new `GetNotificationOptions`."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `GetNotificationOptions`*"] - pub fn new() -> Self { - #[allow(unused_mut)] - let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); - ret - } - #[doc = "Change the `tag` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `GetNotificationOptions`*"] - pub fn tag(&mut self, val: &str) -> &mut Self { - use wasm_bindgen::JsValue; - let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("tag"), &JsValue::from(val)); - debug_assert!( - r.is_ok(), - "setting properties should never fail on our dictionary objects" - ); - let _ = r; - self - } -} -impl Default for GetNotificationOptions { - fn default() -> Self { - Self::new() - } -} diff --git a/crates/web-sys/src/features/gen_Notification.rs b/crates/web-sys/src/features/gen_Notification.rs index 857ad0089c5..746b7d27440 100644 --- a/crates/web-sys/src/features/gen_Notification.rs +++ b/crates/web-sys/src/features/gen_Notification.rs @@ -20,6 +20,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`, `NotificationPermission`*"] pub fn permission() -> NotificationPermission; + # [wasm_bindgen (structural , static_method_of = Notification , getter , js_class = "Notification" , js_name = maxActions)] + #[doc = "Getter for the `maxActions` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/maxActions)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn max_actions() -> u32; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = onclick)] #[doc = "Getter for the `onclick` field of this object."] #[doc = ""] @@ -97,28 +104,70 @@ extern "C" { #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/lang)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn lang(this: &Notification) -> Option; + pub fn lang(this: &Notification) -> String; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = body)] #[doc = "Getter for the `body` field of this object."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/body)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn body(this: &Notification) -> Option; + pub fn body(this: &Notification) -> String; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = tag)] #[doc = "Getter for the `tag` field of this object."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/tag)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn tag(this: &Notification) -> Option; + pub fn tag(this: &Notification) -> String; + # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = image)] + #[doc = "Getter for the `image` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/image)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn image(this: &Notification) -> String; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = icon)] #[doc = "Getter for the `icon` field of this object."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/icon)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn icon(this: &Notification) -> Option; + pub fn icon(this: &Notification) -> String; + # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = badge)] + #[doc = "Getter for the `badge` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/badge)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn badge(this: &Notification) -> String; + # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = vibrate)] + #[doc = "Getter for the `vibrate` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/vibrate)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn vibrate(this: &Notification) -> ::js_sys::Array; + # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = timestamp)] + #[doc = "Getter for the `timestamp` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/timestamp)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn timestamp(this: &Notification) -> f64; + # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = renotify)] + #[doc = "Getter for the `renotify` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/renotify)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn renotify(this: &Notification) -> bool; + # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = silent)] + #[doc = "Getter for the `silent` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/silent)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn silent(this: &Notification) -> Option; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = requireInteraction)] #[doc = "Getter for the `requireInteraction` field of this object."] #[doc = ""] @@ -133,6 +182,13 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] pub fn data(this: &Notification) -> ::wasm_bindgen::JsValue; + # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = actions)] + #[doc = "Getter for the `actions` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/actions)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Notification`*"] + pub fn actions(this: &Notification) -> ::js_sys::Array; #[wasm_bindgen(catch, constructor, js_class = "Notification")] #[doc = "The `new Notification(..)` constructor, creating a new instance of `Notification`."] #[doc = ""] @@ -158,35 +214,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] pub fn close(this: &Notification); - # [wasm_bindgen (catch , static_method_of = Notification , js_class = "Notification" , js_name = get)] - #[doc = "The `get()` method."] - #[doc = ""] - #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/get)"] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn get() -> Result<::js_sys::Promise, JsValue>; - #[cfg(feature = "GetNotificationOptions")] - # [wasm_bindgen (catch , static_method_of = Notification , js_class = "Notification" , js_name = get)] - #[doc = "The `get()` method."] - #[doc = ""] - #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/get)"] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `GetNotificationOptions`, `Notification`*"] - pub fn get_with_filter(filter: &GetNotificationOptions) -> Result<::js_sys::Promise, JsValue>; - # [wasm_bindgen (catch , static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] + # [wasm_bindgen (static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] #[doc = "The `requestPermission()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn request_permission() -> Result<::js_sys::Promise, JsValue>; - # [wasm_bindgen (catch , static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] + pub fn request_permission() -> ::js_sys::Promise; + # [wasm_bindgen (static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] #[doc = "The `requestPermission()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn request_permission_with_permission_callback( - permission_callback: &::js_sys::Function, - ) -> Result<::js_sys::Promise, JsValue>; + pub fn request_permission_with_deprecated_callback( + deprecated_callback: &::js_sys::Function, + ) -> ::js_sys::Promise; } diff --git a/crates/web-sys/src/features/gen_NotificationBehavior.rs b/crates/web-sys/src/features/gen_NotificationBehavior.rs deleted file mode 100644 index 0f11b7e4055..00000000000 --- a/crates/web-sys/src/features/gen_NotificationBehavior.rs +++ /dev/null @@ -1,113 +0,0 @@ -#![allow(unused_imports)] -#![allow(clippy::all)] -use super::*; -use wasm_bindgen::prelude::*; -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = :: js_sys :: Object , js_name = NotificationBehavior)] - #[derive(Debug, Clone, PartialEq, Eq)] - #[doc = "The `NotificationBehavior` dictionary."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `NotificationBehavior`*"] - pub type NotificationBehavior; -} -impl NotificationBehavior { - #[doc = "Construct a new `NotificationBehavior`."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `NotificationBehavior`*"] - pub fn new() -> Self { - #[allow(unused_mut)] - let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); - ret - } - #[doc = "Change the `noclear` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `NotificationBehavior`*"] - pub fn noclear(&mut self, val: bool) -> &mut Self { - use wasm_bindgen::JsValue; - let r = ::js_sys::Reflect::set( - self.as_ref(), - &JsValue::from("noclear"), - &JsValue::from(val), - ); - debug_assert!( - r.is_ok(), - "setting properties should never fail on our dictionary objects" - ); - let _ = r; - self - } - #[doc = "Change the `noscreen` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `NotificationBehavior`*"] - pub fn noscreen(&mut self, val: bool) -> &mut Self { - use wasm_bindgen::JsValue; - let r = ::js_sys::Reflect::set( - self.as_ref(), - &JsValue::from("noscreen"), - &JsValue::from(val), - ); - debug_assert!( - r.is_ok(), - "setting properties should never fail on our dictionary objects" - ); - let _ = r; - self - } - #[doc = "Change the `showOnlyOnce` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `NotificationBehavior`*"] - pub fn show_only_once(&mut self, val: bool) -> &mut Self { - use wasm_bindgen::JsValue; - let r = ::js_sys::Reflect::set( - self.as_ref(), - &JsValue::from("showOnlyOnce"), - &JsValue::from(val), - ); - debug_assert!( - r.is_ok(), - "setting properties should never fail on our dictionary objects" - ); - let _ = r; - self - } - #[doc = "Change the `soundFile` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `NotificationBehavior`*"] - pub fn sound_file(&mut self, val: &str) -> &mut Self { - use wasm_bindgen::JsValue; - let r = ::js_sys::Reflect::set( - self.as_ref(), - &JsValue::from("soundFile"), - &JsValue::from(val), - ); - debug_assert!( - r.is_ok(), - "setting properties should never fail on our dictionary objects" - ); - let _ = r; - self - } - #[doc = "Change the `vibrationPattern` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `NotificationBehavior`*"] - pub fn vibration_pattern(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { - use wasm_bindgen::JsValue; - let r = ::js_sys::Reflect::set( - self.as_ref(), - &JsValue::from("vibrationPattern"), - &JsValue::from(val), - ); - debug_assert!( - r.is_ok(), - "setting properties should never fail on our dictionary objects" - ); - let _ = r; - self - } -} -impl Default for NotificationBehavior { - fn default() -> Self { - Self::new() - } -} diff --git a/crates/web-sys/src/features/gen_NotificationOptions.rs b/crates/web-sys/src/features/gen_NotificationOptions.rs index 5c15dd56bcb..ec01ac68a66 100644 --- a/crates/web-sys/src/features/gen_NotificationOptions.rs +++ b/crates/web-sys/src/features/gen_NotificationOptions.rs @@ -190,6 +190,23 @@ impl NotificationOptions { let _ = r; self } + #[doc = "Change the `timestamp` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"] + pub fn timestamp(&mut self, val: f64) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("timestamp"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } } impl Default for NotificationOptions { fn default() -> Self { diff --git a/crates/web-sys/src/features/gen_ServiceWorkerRegistration.rs b/crates/web-sys/src/features/gen_ServiceWorkerRegistration.rs index 1923ab849c6..5556ea0303b 100644 --- a/crates/web-sys/src/features/gen_ServiceWorkerRegistration.rs +++ b/crates/web-sys/src/features/gen_ServiceWorkerRegistration.rs @@ -84,17 +84,6 @@ extern "C" { pub fn get_notifications( this: &ServiceWorkerRegistration, ) -> Result<::js_sys::Promise, JsValue>; - #[cfg(feature = "GetNotificationOptions")] - # [wasm_bindgen (catch , method , structural , js_class = "ServiceWorkerRegistration" , js_name = getNotifications)] - #[doc = "The `getNotifications()` method."] - #[doc = ""] - #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/getNotifications)"] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `GetNotificationOptions`, `ServiceWorkerRegistration`*"] - pub fn get_notifications_with_filter( - this: &ServiceWorkerRegistration, - filter: &GetNotificationOptions, - ) -> Result<::js_sys::Promise, JsValue>; # [wasm_bindgen (catch , method , structural , js_class = "ServiceWorkerRegistration" , js_name = showNotification)] #[doc = "The `showNotification()` method."] #[doc = ""] diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 9d3be3f2b42..12094200303 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -2476,12 +2476,6 @@ mod gen_GetAnimationsOptions; #[cfg(feature = "GetAnimationsOptions")] pub use gen_GetAnimationsOptions::*; -#[cfg(feature = "GetNotificationOptions")] -#[allow(non_snake_case)] -mod gen_GetNotificationOptions; -#[cfg(feature = "GetNotificationOptions")] -pub use gen_GetNotificationOptions::*; - #[cfg(feature = "GetRootNodeOptions")] #[allow(non_snake_case)] mod gen_GetRootNodeOptions; @@ -5098,12 +5092,6 @@ mod gen_NotificationAction; #[cfg(feature = "NotificationAction")] pub use gen_NotificationAction::*; -#[cfg(feature = "NotificationBehavior")] -#[allow(non_snake_case)] -mod gen_NotificationBehavior; -#[cfg(feature = "NotificationBehavior")] -pub use gen_NotificationBehavior::*; - #[cfg(feature = "NotificationDirection")] #[allow(non_snake_case)] mod gen_NotificationDirection; diff --git a/crates/web-sys/webidls/enabled/Notification.webidl b/crates/web-sys/webidls/enabled/Notification.webidl index 19729174cb5..cb4dd299d1c 100644 --- a/crates/web-sys/webidls/enabled/Notification.webidl +++ b/crates/web-sys/webidls/enabled/Notification.webidl @@ -1,60 +1,32 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * The origin of this IDL file is - * https://notifications.spec.whatwg.org/ - * - * Copyright: - * To the extent possible under law, the editors have waived all copyright and - * related or neighboring rights to this work. - */ - -[Constructor(DOMString title, optional NotificationOptions options), - Exposed=(Window,Worker), - Func="mozilla::dom::Notification::PrefEnabled"] +[Exposed=(Window,Worker)] interface Notification : EventTarget { - [GetterThrows] - static readonly attribute NotificationPermission permission; + constructor(DOMString title, optional NotificationOptions options = {}); - [Throws, Func="mozilla::dom::Notification::RequestPermissionEnabledForScope"] - static Promise requestPermission(optional NotificationPermissionCallback permissionCallback); + static readonly attribute NotificationPermission permission; + [Exposed=Window] static Promise requestPermission(optional NotificationPermissionCallback deprecatedCallback); - [Throws, Func="mozilla::dom::Notification::IsGetEnabled"] - static Promise> get(optional GetNotificationOptions filter); + static readonly attribute unsigned long maxActions; attribute EventHandler onclick; - attribute EventHandler onshow; - attribute EventHandler onerror; - attribute EventHandler onclose; - [Pure] readonly attribute DOMString title; - - [Pure] readonly attribute NotificationDirection dir; - - [Pure] - readonly attribute DOMString? lang; - - [Pure] - readonly attribute DOMString? body; - - [Constant] - readonly attribute DOMString? tag; - - [Pure] - readonly attribute DOMString? icon; - - [Constant, Func="mozilla::dom::DOMPrefs::NotificationRIEnabled"] + readonly attribute DOMString lang; + readonly attribute DOMString body; + readonly attribute DOMString tag; + readonly attribute USVString image; + readonly attribute USVString icon; + readonly attribute USVString badge; + [SameObject] readonly attribute FrozenArray vibrate; + readonly attribute unsigned long long timestamp; + readonly attribute boolean renotify; + readonly attribute boolean? silent; readonly attribute boolean requireInteraction; - - [Constant] - readonly attribute any data; + [SameObject] readonly attribute any data; + [SameObject] readonly attribute FrozenArray actions; undefined close(); }; @@ -67,6 +39,7 @@ dictionary NotificationOptions { USVString image; USVString icon; USVString badge; + unsigned long long timestamp; boolean renotify = false; boolean? silent = null; boolean requireInteraction = false; @@ -74,34 +47,22 @@ dictionary NotificationOptions { sequence actions = []; }; -dictionary GetNotificationOptions { - DOMString tag = ""; -}; - -dictionary NotificationBehavior { - boolean noscreen = false; - boolean noclear = false; - boolean showOnlyOnce = false; - DOMString soundFile = ""; - sequence vibrationPattern; -}; - enum NotificationPermission { "default", "denied", "granted" }; +enum NotificationDirection { + "auto" , + "ltr" , + "rtl" +}; + dictionary NotificationAction { required DOMString action; required DOMString title; USVString icon; }; -callback NotificationPermissionCallback = undefined (NotificationPermission permission); - -enum NotificationDirection { - "auto", - "ltr", - "rtl" -}; +callback NotificationPermissionCallback = undefined (NotificationPermission permission); \ No newline at end of file From 8b37163cbf1b86be9eb13bfd89ab09861ef2e5de Mon Sep 17 00:00:00 2001 From: Marc-Stefan Cassola Date: Wed, 25 Oct 2023 14:38:09 +0100 Subject: [PATCH 3/8] Update crates/web-sys/webidls/enabled/Notification.webidl Co-authored-by: daxpedda --- crates/web-sys/webidls/enabled/Notification.webidl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/web-sys/webidls/enabled/Notification.webidl b/crates/web-sys/webidls/enabled/Notification.webidl index cb4dd299d1c..3dbffdf8758 100644 --- a/crates/web-sys/webidls/enabled/Notification.webidl +++ b/crates/web-sys/webidls/enabled/Notification.webidl @@ -54,8 +54,8 @@ enum NotificationPermission { }; enum NotificationDirection { - "auto" , - "ltr" , + "auto", + "ltr", "rtl" }; From a1673bb9e2524288272e5ea45b2988842186cfbf Mon Sep 17 00:00:00 2001 From: Marc-Stefan Cassola Date: Wed, 25 Oct 2023 14:38:39 +0100 Subject: [PATCH 4/8] Update crates/web-sys/webidls/enabled/Notification.webidl Co-authored-by: daxpedda --- crates/web-sys/webidls/enabled/Notification.webidl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/web-sys/webidls/enabled/Notification.webidl b/crates/web-sys/webidls/enabled/Notification.webidl index 3dbffdf8758..d947a8640ff 100644 --- a/crates/web-sys/webidls/enabled/Notification.webidl +++ b/crates/web-sys/webidls/enabled/Notification.webidl @@ -14,11 +14,11 @@ interface Notification : EventTarget { readonly attribute DOMString title; readonly attribute NotificationDirection dir; - readonly attribute DOMString lang; - readonly attribute DOMString body; - readonly attribute DOMString tag; + readonly attribute DOMString? lang; + readonly attribute DOMString? body; + readonly attribute DOMString? tag; readonly attribute USVString image; - readonly attribute USVString icon; + readonly attribute USVString? icon; readonly attribute USVString badge; [SameObject] readonly attribute FrozenArray vibrate; readonly attribute unsigned long long timestamp; From fedae147087ad892eb95c2092b1c1795ecb8d166 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Wed, 25 Oct 2023 09:07:00 -0500 Subject: [PATCH 5/8] added entries to changelog --- CHANGELOG.md | 3 +++ crates/web-sys/webidls/enabled/Notification.webidl | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da6e2063ded..e1eaa786864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,9 @@ * Removed `ReadableStreamByobReader::read_with_u8_array()` because it doesn't work with Wasm. [#3582](https://github.com/rustwasm/wasm-bindgen/pull/3582) +* Removed `GetNotificationOptions`, `NotificationBehavior` and `Notification.get()` because + they don't exist anymore. + ## [0.2.87](https://github.com/rustwasm/wasm-bindgen/compare/0.2.86...0.2.87) Released 2023-06-12. diff --git a/crates/web-sys/webidls/enabled/Notification.webidl b/crates/web-sys/webidls/enabled/Notification.webidl index d947a8640ff..3114b8cd909 100644 --- a/crates/web-sys/webidls/enabled/Notification.webidl +++ b/crates/web-sys/webidls/enabled/Notification.webidl @@ -3,7 +3,9 @@ interface Notification : EventTarget { constructor(DOMString title, optional NotificationOptions options = {}); static readonly attribute NotificationPermission permission; - [Exposed=Window] static Promise requestPermission(optional NotificationPermissionCallback deprecatedCallback); + + [Throws, Func="mozilla::dom::Notification::RequestPermissionEnabledForScope"] + static Promise requestPermission(optional NotificationPermissionCallback permissionCallback); static readonly attribute unsigned long maxActions; @@ -65,4 +67,4 @@ dictionary NotificationAction { USVString icon; }; -callback NotificationPermissionCallback = undefined (NotificationPermission permission); \ No newline at end of file +callback NotificationPermissionCallback = undefined (NotificationPermission permission); From ecdacf4a6e6df3a63a09da9b21c4cb498f3cfa87 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Wed, 25 Oct 2023 09:10:07 -0500 Subject: [PATCH 6/8] regenerated --- .../web-sys/src/features/gen_Notification.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/web-sys/src/features/gen_Notification.rs b/crates/web-sys/src/features/gen_Notification.rs index 746b7d27440..b0eaed5e807 100644 --- a/crates/web-sys/src/features/gen_Notification.rs +++ b/crates/web-sys/src/features/gen_Notification.rs @@ -104,21 +104,21 @@ extern "C" { #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/lang)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn lang(this: &Notification) -> String; + pub fn lang(this: &Notification) -> Option; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = body)] #[doc = "Getter for the `body` field of this object."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/body)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn body(this: &Notification) -> String; + pub fn body(this: &Notification) -> Option; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = tag)] #[doc = "Getter for the `tag` field of this object."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/tag)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn tag(this: &Notification) -> String; + pub fn tag(this: &Notification) -> Option; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = image)] #[doc = "Getter for the `image` field of this object."] #[doc = ""] @@ -132,7 +132,7 @@ extern "C" { #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/icon)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn icon(this: &Notification) -> String; + pub fn icon(this: &Notification) -> Option; # [wasm_bindgen (structural , method , getter , js_class = "Notification" , js_name = badge)] #[doc = "Getter for the `badge` field of this object."] #[doc = ""] @@ -214,20 +214,20 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] pub fn close(this: &Notification); - # [wasm_bindgen (static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] + # [wasm_bindgen (catch , static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] #[doc = "The `requestPermission()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn request_permission() -> ::js_sys::Promise; - # [wasm_bindgen (static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] + pub fn request_permission() -> Result<::js_sys::Promise, JsValue>; + # [wasm_bindgen (catch , static_method_of = Notification , js_class = "Notification" , js_name = requestPermission)] #[doc = "The `requestPermission()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Notification`*"] - pub fn request_permission_with_deprecated_callback( - deprecated_callback: &::js_sys::Function, - ) -> ::js_sys::Promise; + pub fn request_permission_with_permission_callback( + permission_callback: &::js_sys::Function, + ) -> Result<::js_sys::Promise, JsValue>; } From e11aab0af6cd21173bfe2aaedf0038dc60493187 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Wed, 25 Oct 2023 09:22:48 -0500 Subject: [PATCH 7/8] Update CHANGELOG.md with new additions --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1eaa786864..b722e251fe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,29 @@ proc-macro and accept the `--include-ignored` flag with `wasm-bindgen-test-runner`. [#3644](https://github.com/rustwasm/wasm-bindgen/pull/3644) +* Added `Notification` fields + [#3667](https://github.com/rustwasm/wasm-bindgen/pull/3667) + * `max_actions` + * `image` + * `badge` + * `vibrate` + * `timestamp` + * `renotify` + * `silent` + * `actions` + +* Added `NotificationOptions` fields + [#3667](https://github.com/rustwasm/wasm-bindgen/pull/3667) + * `image` + * `badge` + * `timestamp` + * `renotify` + * `silent` + * `actions` + +* Added `NotificationAction` + [#3667](https://github.com/rustwasm/wasm-bindgen/pull/3667) + ### Changed * Updated the WebGPU WebIDL. From ba5435b0372950e6fdc5ddbc1e2633cac1b36bda Mon Sep 17 00:00:00 2001 From: Marc-Stefan Cassola Date: Wed, 25 Oct 2023 17:11:38 +0100 Subject: [PATCH 8/8] Update CHANGELOG.md Co-authored-by: daxpedda --- CHANGELOG.md | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b722e251fe7..de77040a614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,27 +67,7 @@ proc-macro and accept the `--include-ignored` flag with `wasm-bindgen-test-runner`. [#3644](https://github.com/rustwasm/wasm-bindgen/pull/3644) -* Added `Notification` fields - [#3667](https://github.com/rustwasm/wasm-bindgen/pull/3667) - * `max_actions` - * `image` - * `badge` - * `vibrate` - * `timestamp` - * `renotify` - * `silent` - * `actions` - -* Added `NotificationOptions` fields - [#3667](https://github.com/rustwasm/wasm-bindgen/pull/3667) - * `image` - * `badge` - * `timestamp` - * `renotify` - * `silent` - * `actions` - -* Added `NotificationAction` +* Added missing additions to the Notification API. [#3667](https://github.com/rustwasm/wasm-bindgen/pull/3667) ### Changed