From db763d7290595d2b5c6972b3fc23927b9d39927f Mon Sep 17 00:00:00 2001 From: Tim Gromeyer Date: Tue, 22 Apr 2025 14:06:38 +0200 Subject: [PATCH] [Linux] Add setting to change bluetooth retry attempts --- linux/Main.qml | 14 ++++++++++++++ linux/main.cpp | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/linux/Main.qml b/linux/Main.qml index aa8e115..d4599e8 100644 --- a/linux/Main.qml +++ b/linux/Main.qml @@ -200,6 +200,20 @@ ApplicationWindow { onCheckedChanged: airPodsTrayApp.notificationsEnabled = checked } + Row { + spacing: 5 + Label { + text: "Bluetooth Retry Attempts:" + anchors.verticalCenter: parent.verticalCenter + } + SpinBox { + from: 1 + to: 10 + value: airPodsTrayApp.retryAttempts + onValueChanged: airPodsTrayApp.retryAttempts = value + } + } + Row { spacing: 10 visible: airPodsTrayApp.airpodsConnected diff --git a/linux/main.cpp b/linux/main.cpp index 37e098b..8247212 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -34,6 +34,7 @@ class AirPodsTrayApp : public QObject { Q_PROPERTY(bool crossDeviceEnabled READ crossDeviceEnabled WRITE setCrossDeviceEnabled NOTIFY crossDeviceEnabledChanged) 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) public: AirPodsTrayApp(bool debugMode, QObject *parent = nullptr) @@ -78,6 +79,7 @@ public: // Load settings CrossDevice.isEnabled = loadCrossDeviceEnabled(); setEarDetectionBehavior(loadEarDetectionSettings()); + setRetryAttempts(loadRetryAttempts()); monitor->checkAlreadyConnectedDevices(); LOG_INFO("AirPodsTrayApp initialized"); @@ -136,6 +138,7 @@ public: AutoStartManager *autoStartManager() const { return m_autoStartManager; } bool notificationsEnabled() const { return trayManager->notificationsEnabled(); } void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); } + int retryAttempts() const { return m_retryAttempts; } private: bool debugMode; @@ -214,6 +217,17 @@ public slots: emit conversationalAwarenessChanged(enabled); } + void setRetryAttempts(int attempts) + { + if (m_retryAttempts != attempts) + { + LOG_DEBUG("Setting retry attempts to: " << attempts); + m_retryAttempts = attempts; + emit retryAttemptsChanged(attempts); + saveRetryAttempts(attempts); + } + } + void initiateMagicPairing() { if (!socket || !socket->isOpen()) @@ -319,6 +333,9 @@ public slots: bool loadNotificationsEnabled() const { return m_settings->value("notifications/enabled", true).toBool(); } void saveNotificationsEnabled(bool enabled) { m_settings->setValue("notifications/enabled", enabled); } + int loadRetryAttempts() const { return m_settings->value("bluetooth/retryAttempts", 3).toInt(); } + void saveRetryAttempts(int attempts) { m_settings->setValue("bluetooth/retryAttempts", attempts); } + private slots: void onTrayIconActivated() { @@ -522,7 +539,7 @@ private slots: LOG_ERROR("Socket error: " << error << ", " << localSocket->errorString()); static int retryCount = 0; - if (retryCount < 3) + if (retryCount < m_retryAttempts) { retryCount++; LOG_INFO("Retrying connection (attempt " << retryCount << ")"); @@ -866,6 +883,7 @@ signals: void earDetectionBehaviorChanged(int behavior); void crossDeviceEnabledChanged(bool enabled); void notificationsEnabledChanged(bool enabled); + void retryAttemptsChanged(int attempts); private: QBluetoothSocket *socket = nullptr; @@ -878,6 +896,7 @@ private: BluetoothMonitor *monitor; QSettings *m_settings; AutoStartManager *m_autoStartManager; + int m_retryAttempts = 3; QString m_batteryStatus; QString m_earDetectionStatus;