mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +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
+14
-4
@@ -26,7 +26,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
get_daemon_config(); // Initialize daemon config
|
||||
create_virtual_mic()?;
|
||||
get_audio_player().await; // Initialize audio player
|
||||
if let Err(err) = get_audio_player().await {
|
||||
eprintln!("Failed to initialize audio player: {}", err);
|
||||
} // Initialize audio player
|
||||
|
||||
let max_retries = 5;
|
||||
for i in 0..=max_retries {
|
||||
@@ -156,9 +158,17 @@ async fn commands_loop(listener: UnixListener) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
async fn player_loop() {
|
||||
loop {
|
||||
let mut audio_player = get_audio_player().await.lock().await;
|
||||
|
||||
audio_player.update().await;
|
||||
match get_audio_player().await {
|
||||
Ok(player_mutex) => {
|
||||
let mut audio_player = player_mutex.lock().await;
|
||||
audio_player.update().await;
|
||||
}
|
||||
Err(_err) => {
|
||||
// To avoid spamming logs every 100ms when audio player fails to init
|
||||
// we can just sleep, or you might prefer to print the error.
|
||||
// Assuming it failed to initialize, no player update is possible.
|
||||
}
|
||||
}
|
||||
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user