Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions linux/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ ApplicationWindow {
onCheckedChanged: airPodsTrayApp.notificationsEnabled = checked
}

Switch {
text: qsTr("Take Over Audio When Media Plays")
checked: airPodsTrayApp.mediaTakeoverEnabled
onCheckedChanged: airPodsTrayApp.mediaTakeoverEnabled = checked

ToolTip {
visible: parent.hovered
text: qsTr("Automatically connect to the AirPods and take audio from\nother devices when media starts playing on this computer")
delay: 500
}
}

Switch {
visible: airPodsTrayApp.airpodsConnected
text: qsTr("One Bud ANC Mode")
Expand Down
23 changes: 23 additions & 0 deletions linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AirPodsTrayApp : public QObject {
Q_PROPERTY(AutoStartManager *autoStartManager READ autoStartManager CONSTANT)
Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
Q_PROPERTY(int retryAttempts READ retryAttempts WRITE setRetryAttempts NOTIFY retryAttemptsChanged)
Q_PROPERTY(bool mediaTakeoverEnabled READ mediaTakeoverEnabled WRITE setMediaTakeoverEnabled NOTIFY mediaTakeoverEnabledChanged)
Q_PROPERTY(bool hideOnStart READ hideOnStart CONSTANT)
Q_PROPERTY(DeviceInfo *deviceInfo READ deviceInfo CONSTANT)
Q_PROPERTY(QString phoneMacStatus READ phoneMacStatus NOTIFY phoneMacStatusChanged)
Expand Down Expand Up @@ -90,6 +91,7 @@ class AirPodsTrayApp : public QObject {
CrossDevice.isEnabled = loadCrossDeviceEnabled();
setEarDetectionBehavior(loadEarDetectionSettings());
setRetryAttempts(loadRetryAttempts());
m_mediaTakeoverEnabled = loadMediaTakeoverEnabled();

monitor->checkAlreadyConnectedDevices();
LOG_INFO("AirPodsTrayApp initialized");
Expand Down Expand Up @@ -133,6 +135,7 @@ class AirPodsTrayApp : public QObject {
bool notificationsEnabled() const { return trayManager->notificationsEnabled(); }
void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); }
int retryAttempts() const { return m_retryAttempts; }
bool mediaTakeoverEnabled() const { return m_mediaTakeoverEnabled; }
bool hideOnStart() const { return m_hideOnStart; }
DeviceInfo *deviceInfo() const { return m_deviceInfo; }
QString phoneMacStatus() const { return m_phoneMacStatus; }
Expand Down Expand Up @@ -249,6 +252,17 @@ public slots:
}
}

void setMediaTakeoverEnabled(bool enabled)
{
if (m_mediaTakeoverEnabled != enabled)
{
LOG_DEBUG("Setting media takeover to: " << enabled);
m_mediaTakeoverEnabled = enabled;
emit mediaTakeoverEnabledChanged(enabled);
saveMediaTakeoverEnabled(enabled);
}
}

void initiateMagicPairing()
{
if (!socket || !socket->isOpen())
Expand Down Expand Up @@ -410,6 +424,9 @@ public slots:
int loadRetryAttempts() const { return m_settings->value("bluetooth/retryAttempts", 3).toInt(); }
void saveRetryAttempts(int attempts) { m_settings->setValue("bluetooth/retryAttempts", attempts); }

bool loadMediaTakeoverEnabled() const { return m_settings->value("media/takeoverEnabled", true).toBool(); }
void saveMediaTakeoverEnabled(bool enabled) { m_settings->setValue("media/takeoverEnabled", enabled); }

void onSystemGoingToSleep()
{
if (m_bleManager->isScanning())
Expand Down Expand Up @@ -887,6 +904,10 @@ private slots:
public:
void handleMediaStateChange(MediaController::MediaState state) {
if (state == MediaController::MediaState::Playing) {
if (!m_mediaTakeoverEnabled) {
LOG_DEBUG("Media started playing, but media takeover is disabled");
return;
}
LOG_INFO("Media started playing, sending disconnect request to Android and taking over audio");
sendDisconnectRequestToAndroid();
connectToAirPods(true);
Expand Down Expand Up @@ -966,6 +987,7 @@ private slots:
void crossDeviceEnabledChanged(bool enabled);
void notificationsEnabledChanged(bool enabled);
void retryAttemptsChanged(int attempts);
void mediaTakeoverEnabledChanged(bool enabled);
void oneBudANCModeChanged(bool enabled);
void phoneMacStatusChanged();
void hearingAidEnabledChanged(bool enabled);
Expand All @@ -981,6 +1003,7 @@ private slots:
QSettings *m_settings;
AutoStartManager *m_autoStartManager;
int m_retryAttempts = 3;
bool m_mediaTakeoverEnabled = true;
bool m_hideOnStart = false;
DeviceInfo *m_deviceInfo;
BleManager *m_bleManager;
Expand Down