Add background playback toggle and fix tab-switch audio overlap#79
Add background playback toggle and fix tab-switch audio overlap#79ru-aish wants to merge 2 commits intorichardr1126:mainfrom
Conversation
|
@ru-aish is attempting to deploy a commit to the richardr1126's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughAdds a new boolean config flag Changes
Sequence DiagramsequenceDiagram
participant User
participant SettingsUI as "Settings UI"
participant Config as "ConfigContext"
participant TTS as "TTSContext"
participant BG as "useBackgroundState"
participant Audio
User->>SettingsUI: Toggle "Keep playing in background"
SettingsUI->>Config: updateConfigKey('keepPlayingInBackground', value)
Config->>TTS: context value updated
TTS->>BG: keepPlayingInBackground observed
Note over User,Audio: Document visibility changes
User->>Audio: Document hidden (visibilitychange)
Audio->>BG: notify visibility change
alt keepPlayingInBackground == true
BG->>Audio: Do not pause — continue playback
else keepPlayingInBackground == false
BG->>Audio: Pause playback
end
Note over User,Audio: Document returns to foreground
User->>Audio: Document visible
Audio->>BG: notify visibility change
BG->>Audio: Resume if conditions met
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/hooks/audio/useBackgroundState.ts`:
- Around line 37-50: The effect in useBackgroundState that watches [activeHowl,
isPlaying, keepPlayingInBackground] can cause double-play when a new Howl is
created while the tab is hidden; remove this entire effect block to avoid
calling activeHowl.play() a second time and rely on the existing playback driver
in TTSContext (playAudio → playSentenceWithHowl → howl.play) and the existing
visibilitychange effect to manage pause/resume behavior.
🧹 Nitpick comments (1)
src/hooks/audio/useBackgroundState.ts (1)
13-35: Visibility handler resumes audio unconditionally on foreground return, even whenkeepPlayingInBackgroundis true.When
keepPlayingInBackgroundis true and audio is already playing in the background, theelse if (isPlaying)branch (line 23) fires on foreground return and callsactiveHowl.play(). While the!activeHowl.playing()guard on line 25 prevents a double-play if the howl is currently playing, there could be a brief window (e.g., between sentences) where the howl is null or not playing, potentially causing unexpected behavior.This is minor given the guard, but worth noting that the
else ifon line 23 also matches the case wheredocument.hidden && keepPlayingInBackground— consider making the foreground case explicit:♻️ More explicit branching
const handleVisibilityChange = () => { setIsBackgrounded(document.hidden); if (document.hidden && !keepPlayingInBackground) { // When backgrounded, pause audio but maintain isPlaying state if (activeHowl?.playing()) { activeHowl.pause(); } - } else if (isPlaying) { + } else if (!document.hidden && isPlaying) { // When returning to foreground, resume from current position if (activeHowl && !activeHowl.playing()) { activeHowl.play(); } } };
Summary:
Why:
Validation:
Summary by CodeRabbit