From be3618e8c4eb1a9ab71011e933b7479f7273cf76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Fri, 24 Jul 2026 14:03:16 +0200 Subject: [PATCH] linux-rust: refresh the audio card index on activation PipeWire assigns a new card index when AirPods reconnect, so the cached value can point at a card that no longer exists. Resolve the card by Bluetooth MAC before every A2DP activation and update the cached index for the remaining profile operations. --- linux-rust/src/media_controller.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/linux-rust/src/media_controller.rs b/linux-rust/src/media_controller.rs index 5bd68b1a2..8307b6e6e 100644 --- a/linux-rust/src/media_controller.rs +++ b/linux-rust/src/media_controller.rs @@ -310,18 +310,18 @@ impl MediaController { return; } - let device_index = state.device_index; let mac = state.connected_device_mac.clone(); drop(state); - let mut current_device_index = device_index; - - if current_device_index.is_none() { - warn!("Device index not found, trying to get it."); - current_device_index = self.get_audio_device_index(&mac).await; - if let Some(idx) = current_device_index { + // The card index changes on every reconnect, so a cached index goes + // stale as soon as the AirPods drop and come back -- and a stale index + // makes every check below fail against a nonexistent card. Resolve it + // fresh by MAC each time instead. + match self.get_audio_device_index(&mac).await { + Some(idx) => { self.state.lock().await.device_index = Some(idx); - } else { + } + None => { warn!("Could not get device index. Cannot activate A2DP profile."); return; } @@ -1079,4 +1079,4 @@ async fn get_sink_name_by_mac(mac: &str) -> Option { }) .await .unwrap_or(None) -} \ No newline at end of file +}