From 1dea701856f22a9040d19ca2fb4e7ed428bab727 Mon Sep 17 00:00:00 2001 From: Christian Lewe Date: Sun, 17 Nov 2024 03:14:52 +0100 Subject: [PATCH] chore: move fallible code to end of function 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 --- src/components/program_window/program_tab.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/program_window/program_tab.rs b/src/components/program_window/program_tab.rs index f60d59f..242dd46 100644 --- a/src/components/program_window/program_tab.rs +++ b/src/components/program_window/program_tab.rs @@ -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()); } @@ -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) {