Skip to content

fix(audio): keep splash close from stopping playback#35

Merged
InstaZDLL merged 1 commit into
mainfrom
fix-splash-audio-shutdown
May 17, 2026
Merged

fix(audio): keep splash close from stopping playback#35
InstaZDLL merged 1 commit into
mainfrom
fix-splash-audio-shutdown

Conversation

@InstaZDLL
Copy link
Copy Markdown
Owner

@InstaZDLL InstaZDLL commented May 17, 2026

Summary

  • Prevent non-main window destruction, including the splashscreen and mini-player, from shutting down the audio engine.
  • Keep WASAPI Exclusive's requested preference separate from the output mode that actually engaged after fallback.
  • Catch decoder-thread panics so playback failures are surfaced as player:error instead of leaving a closed command channel.

Verification

  • cargo check --manifest-path src-tauri/Cargo.toml --all-targets

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced audio decoder resilience through improved error handling to prevent playback disruptions from causing silent failures
    • Corrected accuracy of audio output mode status tracking to properly reflect system configuration
    • Refined application shutdown logic to ensure graceful termination only when the primary window is closed, preventing unintended shutdowns in multi-window scenarios

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

Warning

Rate limit exceeded

@InstaZDLL has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 20 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0d45babc-8cfa-4f9e-ac86-889c6704339c

📥 Commits

Reviewing files that changed from the base of the PR and between 305c68f and 27cfdf7.

📒 Files selected for processing (5)
  • src-tauri/src/audio/decoder.rs
  • src-tauri/src/audio/engine.rs
  • src-tauri/src/audio/output.rs
  • src-tauri/src/audio/wasapi_exclusive.rs
  • src-tauri/src/lib.rs
📝 Walkthrough

Walkthrough

The PR hardens the audio system and improves lifecycle safety: decoder panics are now caught and reported rather than silently killing the thread; WASAPI exclusive mode state is tracked accurately across output initialization, device switching, and preference changes; and window destruction events are filtered to prevent spurious audio shutdown on non-main window close.

Changes

Audio System Reliability and State Integrity

Layer / File(s) Summary
Decoder thread panic recovery
src-tauri/src/audio/decoder.rs
spawn_decoder_thread wraps decoder_loop in catch_unwind; on panic, emits error event, transitions playback to idle, and exits gracefully. Adds panic_payload_message helper and refactors decoder_loop to borrow resources instead of taking ownership.
Active WASAPI exclusive mode state tracking
src-tauri/src/audio/output.rs, src-tauri/src/audio/wasapi_exclusive.rs, src-tauri/src/audio/engine.rs
OutputHandle gains wasapi_exclusive field set by both exclusive and non-exclusive output paths. Engine introduces wasapi_exclusive_active atomic to track actual mode during initialization, device hot-swap, and preference toggle, updating via Release ordering and reading via Acquire. Public accessor now returns active state instead of preference only.
Window destruction shutdown safety
src-tauri/src/lib.rs
WindowEvent::Destroyed handler now filters to main window only and requires QuitGate to be armed before proceeding; gates resume persistence and audio shutdown to prevent unintended triggers on non-main window close.

Sequence Diagram

sequenceDiagram
  participant DecoderSpawner
  participant DecoderThread
  participant CatchUnwind
  participant AudioEngine
  participant Analytics
  DecoderSpawner->>DecoderThread: spawn_decoder_thread
  DecoderThread->>CatchUnwind: catch_unwind(decoder_loop)
  CatchUnwind->>DecoderThread: panic occurs
  DecoderThread->>AudioEngine: emit EVENT_ERROR with crash message
  DecoderThread->>AudioEngine: transition to PlayerState::Idle
  DecoderThread->>Analytics: send error context
  DecoderThread->>DecoderThread: exit gracefully via loop break
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 A decoder that panics? No more!
With catch_unwind we restore the core—
WASAPI modes tracked without a glitch,
Windows gated safe (the main one rich),
Audio flows steady, state rings true! 🎵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change described in pr_objectives: preventing non-main window destruction from shutting down audio, which is the primary user-facing issue being fixed.
Description check ✅ Passed The description covers all three major objectives (splash screen issue, WASAPI Exclusive tracking, decoder panic handling) and includes verification steps, though testing details are minimal.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-splash-audio-shutdown

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@InstaZDLL InstaZDLL self-assigned this May 17, 2026
@github-actions github-actions Bot added scope: backend Rust/Tauri backend (src-tauri/) type: fix Bug fix size: m 50-200 lines labels May 17, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src-tauri/src/audio/decoder.rs`:
- Around line 121-145: The recovery loop around catch_unwind(decoder_loop(...))
can spin indefinitely on persistent panics; modify the loop in the decoder
thread to add a capped retry count and exponential backoff (e.g., track retries,
sleep between attempts) and stop retrying after the max (emit a final
EVENT_ERROR/ErrorPayload, call transition_state(&shared, &app,
PlayerState::Idle, None) and break or return), ensure you still capture the
panic message via panic_payload_message and log it with tracing::error before
sleeping/retrying, and reset retry count on a successful Ok(()) return.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b0a13e6c-f0ef-4c65-8aa2-2a2fdb9b6cf6

📥 Commits

Reviewing files that changed from the base of the PR and between af719b6 and 305c68f.

📒 Files selected for processing (5)
  • src-tauri/src/audio/decoder.rs
  • src-tauri/src/audio/engine.rs
  • src-tauri/src/audio/output.rs
  • src-tauri/src/audio/wasapi_exclusive.rs
  • src-tauri/src/lib.rs

Comment thread src-tauri/src/audio/decoder.rs
@InstaZDLL InstaZDLL force-pushed the fix-splash-audio-shutdown branch from 305c68f to 27cfdf7 Compare May 17, 2026 08:13
@InstaZDLL InstaZDLL merged commit a4fdaa9 into main May 17, 2026
12 of 13 checks passed
@InstaZDLL InstaZDLL deleted the fix-splash-audio-shutdown branch May 17, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: backend Rust/Tauri backend (src-tauri/) size: m 50-200 lines type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant