mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-06-19 12:13:32 +00:00
🧹 Code Health: Handle AudioPlayer initialization errors safely (#35)
* 🧹 Refactor: Replace unsafe unwrap in get_audio_player Co-authored-by: arabianq <55220741+arabianq@users.noreply.github.com> * 🧹 Refactor: Replace unsafe unwrap in get_audio_player Resolved GitHub CI failure where a syntax error was introduced due to a bad automated merge with main. Rebased cleanly to ensure only the get_audio_player code health changes are included. Co-authored-by: arabianq <55220741+arabianq@users.noreply.github.com> * Delete tests/perf_play.rs --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
c6577cd5e0
commit
261f83efd4
+6
-3
@@ -17,11 +17,14 @@ use tokio::{
|
||||
|
||||
static AUDIO_PLAYER: OnceCell<Mutex<AudioPlayer>> = OnceCell::const_new();
|
||||
|
||||
pub async fn get_audio_player() -> &'static Mutex<AudioPlayer> {
|
||||
pub async fn get_audio_player() -> Result<&'static Mutex<AudioPlayer>, String> {
|
||||
AUDIO_PLAYER
|
||||
.get_or_init(|| async {
|
||||
.get_or_try_init(|| async {
|
||||
println!("Initializing audio player");
|
||||
Mutex::new(AudioPlayer::new().await.unwrap())
|
||||
match AudioPlayer::new().await {
|
||||
Ok(player) => Ok(Mutex::new(player)),
|
||||
Err(err) => Err(err.to_string()),
|
||||
}
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user