From c2db0afdf18ee1ea9560d2abec4c1df8d0564980 Mon Sep 17 00:00:00 2001 From: Tim Gromeyer Date: Fri, 18 Apr 2025 17:28:37 +0200 Subject: [PATCH] [Linux] Activate AirPods as output device when connecting --- linux/main.cpp | 7 ++++++- linux/mediacontroller.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/linux/main.cpp b/linux/main.cpp index 01ee3a2..f6df035 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -320,6 +320,7 @@ private slots: // Clear the device name and model m_deviceName.clear(); connectedDeviceMacAddress.clear(); + mediaController->setConnectedDeviceMacAddress(connectedDeviceMacAddress); m_model = AirPodsModel::Unknown; emit deviceNameChanged(m_deviceName); emit modelChanged(); @@ -500,7 +501,6 @@ private slots: localSocket->connectToService(device.address(), QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a")); connectedDeviceMacAddress = device.address().toString().replace(":", "_"); - mediaController->setConnectedDeviceMacAddress(connectedDeviceMacAddress); notifyAndroidDevice(); } @@ -600,6 +600,11 @@ private slots: { parseMetadata(data); initiateMagicPairing(); + mediaController->setConnectedDeviceMacAddress(connectedDeviceMacAddress); + if (isLeftPodInEar() || isRightPodInEar()) // AirPods get added as output device only after this + { + mediaController->activateA2dpProfile(); + } emit airPodsStatusChanged(); } else diff --git a/linux/mediacontroller.cpp b/linux/mediacontroller.cpp index d3ceb26..e52c119 100644 --- a/linux/mediacontroller.cpp +++ b/linux/mediacontroller.cpp @@ -145,6 +145,11 @@ void MediaController::handleConversationalAwareness(const QByteArray &data) { } void MediaController::activateA2dpProfile() { + if (connectedDeviceMacAddress.isEmpty()) { + LOG_WARN("Connected device MAC address is empty, cannot activate A2DP profile"); + return; + } + LOG_INFO("Activating A2DP profile for AirPods"); int result = QProcess::execute( "pactl", QStringList() @@ -156,6 +161,11 @@ void MediaController::activateA2dpProfile() { } void MediaController::removeAudioOutputDevice() { + if (connectedDeviceMacAddress.isEmpty()) { + LOG_WARN("Connected device MAC address is empty, cannot remove audio output device"); + return; + } + LOG_INFO("Removing AirPods as audio output device"); int result = QProcess::execute( "pactl", QStringList()