Skip to content

Commit 2efd450

Browse files
authored
Add bindings to NavigatorOptions.vibrate (#4041)
1 parent f6bcfd0 commit 2efd450

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
* 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.
6767
[#4038](https://github.com/rustwasm/wasm-bindgen/pull/4038)
6868

69+
* Added bindings to `NavigatorOptions.vibrate`.
70+
[#4041](https://github.com/rustwasm/wasm-bindgen/pull/4041)
71+
6972
### Changed
7073

7174
* Stabilize Web Share API.

crates/web-sys/src/features/gen_Navigator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ extern "C" {
533533
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)"]
534534
#[doc = ""]
535535
#[doc = "*This API requires the following crate features to be activated: `Navigator`*"]
536-
pub fn vibrate_with_duration(this: &Navigator, duration: u32) -> bool;
536+
pub fn vibrate_with_duration(this: &Navigator, pattern: u32) -> bool;
537537
# [wasm_bindgen (method , structural , js_class = "Navigator" , js_name = vibrate)]
538538
#[doc = "The `vibrate()` method."]
539539
#[doc = ""]

crates/web-sys/src/features/gen_NotificationOptions.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ extern "C" {
142142
#[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"]
143143
#[wasm_bindgen(method, setter = "timestamp")]
144144
pub fn set_timestamp(this: &NotificationOptions, val: f64);
145+
#[doc = "Get the `vibrate` field of this object."]
146+
#[doc = ""]
147+
#[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"]
148+
#[wasm_bindgen(method, getter = "vibrate")]
149+
pub fn get_vibrate(this: &NotificationOptions) -> ::wasm_bindgen::JsValue;
150+
#[doc = "Change the `vibrate` field of this object."]
151+
#[doc = ""]
152+
#[doc = "*This API requires the following crate features to be activated: `NotificationOptions`*"]
153+
#[wasm_bindgen(method, setter = "vibrate")]
154+
pub fn set_vibrate(this: &NotificationOptions, val: &::wasm_bindgen::JsValue);
145155
}
146156
impl NotificationOptions {
147157
#[doc = "Construct a new `NotificationOptions`."]
@@ -218,6 +228,11 @@ impl NotificationOptions {
218228
self.set_timestamp(val);
219229
self
220230
}
231+
#[deprecated = "Use `set_vibrate()` instead."]
232+
pub fn vibrate(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
233+
self.set_vibrate(val);
234+
self
235+
}
221236
}
222237
impl Default for NotificationOptions {
223238
fn default() -> Self {

crates/web-sys/webidls/enabled/Navigator.webidl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,6 @@ partial interface Navigator {
134134
Promise<BatteryManager> getBattery();
135135
};
136136

137-
// http://www.w3.org/TR/vibration/#vibration-interface
138-
partial interface Navigator {
139-
// We don't support sequences in unions yet
140-
//boolean vibrate ((unsigned long or sequence<unsigned long>) pattern);
141-
boolean vibrate(unsigned long duration);
142-
boolean vibrate(sequence<unsigned long> pattern);
143-
};
144-
145137
// http://www.w3.org/TR/pointerevents/#extensions-to-the-navigator-interface
146138
partial interface Navigator {
147139
[Pref="dom.w3c_pointer_events.enabled"]

crates/web-sys/webidls/enabled/Notification.webidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dictionary NotificationOptions {
4141
USVString image;
4242
USVString icon;
4343
USVString badge;
44+
VibratePattern vibrate = [];
4445
unsigned long long timestamp;
4546
boolean renotify = false;
4647
boolean? silent = null;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// https://www.w3.org/TR/vibration/#vibration-interface
2+
3+
typedef (unsigned long or sequence<unsigned long>) VibratePattern;
4+
5+
partial interface Navigator {
6+
boolean vibrate(VibratePattern pattern);
7+
};

crates/webidl/src/constants.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ pub(crate) static FIXED_INTERFACES: Lazy<
230230
),
231231
]),
232232
),
233+
(
234+
"Navigator",
235+
BTreeMap::from_iter([
236+
("vibrate_with_u32", "vibrate_with_duration"),
237+
("vibrate_with_u32_sequence", "vibrate_with_pattern"),
238+
]),
239+
),
233240
])
234241
});
235242

0 commit comments

Comments
 (0)