mirror of
https://github.com/SrIzan10/lofi.git
synced 2026-06-06 00:56:53 +00:00
fix: race conditions
This commit is contained in:
@@ -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 @@
|
||||
</script>
|
||||
|
||||
{#if !state.hasInteracted}
|
||||
<button class="flex flex-col h-screen w-full items-center justify-center space-y-2 cursor-pointer" onclick={() => {
|
||||
state.hasInteracted = true;
|
||||
if (state.isPlaying) {
|
||||
playAudio();
|
||||
}
|
||||
}}>
|
||||
<button class="flex flex-col h-screen w-full items-center justify-center space-y-2 cursor-pointer" onclick={handleInteraction}>
|
||||
<p>Click anywhere on the screen</p>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user