Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add vibrate field to NotificationOptions in web-sys crate #4041

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
* Added an official MSRV policy. Library MSRV changes will be accompanied by a minor version bump. CLI tool MSRV can change with any version bump.
[#4038](https://github.com/rustwasm/wasm-bindgen/pull/4038)

* Added bindings to `NavigatorOptions.vibrate`.
[#4041](https://github.com/rustwasm/wasm-bindgen/pull/4041)

### Changed

* Stabilize Web Share API.
Expand Down
2 changes: 1 addition & 1 deletion crates/web-sys/src/features/gen_Navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ extern "C" {
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Navigator`*"]
pub fn vibrate_with_duration(this: &Navigator, duration: u32) -> bool;
pub fn vibrate_with_duration(this: &Navigator, pattern: u32) -> bool;
# [wasm_bindgen (method , structural , js_class = "Navigator" , js_name = vibrate)]
#[doc = "The `vibrate()` method."]
#[doc = ""]
Expand Down
15 changes: 15 additions & 0 deletions crates/web-sys/src/features/gen_NotificationOptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ extern "C" {
#[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"]
#[wasm_bindgen(method, setter = "timestamp")]
pub fn set_timestamp(this: &NotificationOptions, val: f64);
#[doc = "Get the `vibrate` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"]
#[wasm_bindgen(method, getter = "vibrate")]
pub fn get_vibrate(this: &NotificationOptions) -> ::wasm_bindgen::JsValue;
#[doc = "Change the `vibrate` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"]
#[wasm_bindgen(method, setter = "vibrate")]
pub fn set_vibrate(this: &NotificationOptions, val: &::wasm_bindgen::JsValue);
}
impl NotificationOptions {
#[doc = "Construct a new `NotificationOptions`."]
Expand Down Expand Up @@ -218,6 +228,11 @@ impl NotificationOptions {
self.set_timestamp(val);
self
}
#[deprecated = "Use `set_vibrate()` instead."]
pub fn vibrate(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
self.set_vibrate(val);
self
}
}
impl Default for NotificationOptions {
fn default() -> Self {
Expand Down
8 changes: 0 additions & 8 deletions crates/web-sys/webidls/enabled/Navigator.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ partial interface Navigator {
Promise<BatteryManager> getBattery();
};

// http://www.w3.org/TR/vibration/#vibration-interface
partial interface Navigator {
// We don't support sequences in unions yet
//boolean vibrate ((unsigned long or sequence<unsigned long>) pattern);
boolean vibrate(unsigned long duration);
boolean vibrate(sequence<unsigned long> pattern);
};

// http://www.w3.org/TR/pointerevents/#extensions-to-the-navigator-interface
partial interface Navigator {
[Pref="dom.w3c_pointer_events.enabled"]
Expand Down
1 change: 1 addition & 0 deletions crates/web-sys/webidls/enabled/Notification.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dictionary NotificationOptions {
USVString image;
USVString icon;
USVString badge;
VibratePattern vibrate = [];
unsigned long long timestamp;
boolean renotify = false;
boolean? silent = null;
Expand Down
7 changes: 7 additions & 0 deletions crates/web-sys/webidls/enabled/Vibration.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// https://www.w3.org/TR/vibration/#vibration-interface

typedef (unsigned long or sequence<unsigned long>) VibratePattern;

partial interface Navigator {
boolean vibrate(VibratePattern pattern);
};
7 changes: 7 additions & 0 deletions crates/webidl/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ pub(crate) static FIXED_INTERFACES: Lazy<
),
]),
),
(
"Navigator",
BTreeMap::from_iter([
("vibrate_with_u32", "vibrate_with_duration"),
("vibrate_with_u32_sequence", "vibrate_with_pattern"),
]),
),
])
});

Expand Down