From 9bd91d2c046f60b300ff3e6cd31c0509b91056c0 Mon Sep 17 00:00:00 2001 From: Alanna Tempest Date: Sun, 18 Jan 2026 13:11:12 -0500 Subject: [PATCH] feat(ui): prompt before closing window if music is playing (#4899) * feat(ui): prompt before closing window if music is playing - #4898 * simplify logic --- ui/src/audioplayer/Player.jsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ui/src/audioplayer/Player.jsx b/ui/src/audioplayer/Player.jsx index 03419add..7d086172 100644 --- a/ui/src/audioplayer/Player.jsx +++ b/ui/src/audioplayer/Player.jsx @@ -95,6 +95,19 @@ const Player = () => { } }, [audioInstance, context, gainNode, playerState, gainInfo]) + useEffect(() => { + const handleBeforeUnload = (e) => { + // Check there's a current track and is actually playing/not paused + if (playerState.current?.uuid && audioInstance && !audioInstance.paused) { + e.preventDefault() + e.returnValue = '' // Chrome requires returnValue to be set + } + } + + window.addEventListener('beforeunload', handleBeforeUnload) + return () => window.removeEventListener('beforeunload', handleBeforeUnload) + }, [playerState, audioInstance]) + const defaultOptions = useMemo( () => ({ theme: playerTheme,