fix(linux-rust): Prevent pulseaudio panic from crashing app (#443)

Wrap set_card_profile_sync call in std::panic::catch_unwind to handle
panics in libpulse-binding when deactivating A2DP profile.
This commit is contained in:
John Sanchirico
2026-02-01 22:08:01 -05:00
committed by GitHub
parent c852b726de
commit 7ab8bd7240

View File

@@ -902,8 +902,16 @@ impl MediaController {
info!("Deactivating A2DP profile for AirPods by setting to off");
// Use catch_unwind to prevent panics in libpulse-binding from crashing the app
let success =
tokio::task::spawn_blocking(move || set_card_profile_sync(device_index, "off"))
tokio::task::spawn_blocking(move || {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
set_card_profile_sync(device_index, "off")
})).unwrap_or_else(|e| {
warn!("Panic in set_card_profile_sync: {:?}", e);
false
})
})
.await
.unwrap_or(false);