From 901d85381de2de63783c7a01f1cc0ca9e8bb170b Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:05:57 +0200 Subject: [PATCH] fix: race conditions --- src/lib/components/app/daemon.svelte | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib/components/app/daemon.svelte b/src/lib/components/app/daemon.svelte index f6c33da..2704b0f 100644 --- a/src/lib/components/app/daemon.svelte +++ b/src/lib/components/app/daemon.svelte @@ -5,6 +5,7 @@ // svelte-ignore non_reactive_update let audioElement: HTMLAudioElement; + let isInteracting = false; // Flag to prevent multiple interactions function togglePlayback(play: boolean) { if (!audioElement) return; @@ -29,6 +30,22 @@ togglePlayback(state.isPlaying); }; + function handleInteraction() { + if (isInteracting) return; + + isInteracting = true; + state.hasInteracted = true; + + if (state.isPlaying) { + setTimeout(() => { + playAudio(); + isInteracting = false; + }, 100); + } else { + isInteracting = false; + } + } + onMount(async () => { const data = await getGeneralData(); state.presets = data.presets; @@ -81,12 +98,7 @@ {#if !state.hasInteracted} - {/if}