Skip to content

Commit

Permalink
chore: move fallible code to end of function
Browse files Browse the repository at this point in the history
Navigator::vibrate_with_duration fails unexpectedly on platforms that
don't support vibration. The expected behavior would be a NOP without
failure. This might be a bug in wasm-bindgen. I will check again after
updating leptos to 0.7.

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate
  • Loading branch information
uncomputable committed Nov 17, 2024
1 parent ccdf0b8 commit 1dea701
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/components/program_window/program_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ impl Runtime {
}

fn set_success(self, success: bool) {
web_sys::window()
.as_ref()
.map(web_sys::Window::navigator)
.map(|navigator| match success {
true => navigator.vibrate_with_duration(200),
false => navigator.vibrate_with_duration(500),
});
if !success {
self.alarm_audio_ref.get().map(|audio| audio.play());
}
Expand All @@ -119,6 +112,13 @@ impl Runtime {
gloo_timers::future::TimeoutFuture::new(500).await;
self.run_succeeded.set(None);
});
web_sys::window()
.as_ref()
.map(web_sys::Window::navigator)
.map(|navigator| match success {
true => navigator.vibrate_with_duration(200),
false => navigator.vibrate_with_duration(500),
});
}

pub fn run(self) {
Expand Down

0 comments on commit 1dea701

Please sign in to comment.