[Linux] Add setting to change bluetooth retry attempts

This commit is contained in:
Tim Gromeyer
2025-04-22 14:06:38 +02:00
committed by Tim Gromeyer
parent 913e1a5aff
commit db763d7290
2 changed files with 34 additions and 1 deletions

View File

@@ -200,6 +200,20 @@ ApplicationWindow {
onCheckedChanged: airPodsTrayApp.notificationsEnabled = checked 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 { Row {
spacing: 10 spacing: 10
visible: airPodsTrayApp.airpodsConnected visible: airPodsTrayApp.airpodsConnected

View File

@@ -34,6 +34,7 @@ class AirPodsTrayApp : public QObject {
Q_PROPERTY(bool crossDeviceEnabled READ crossDeviceEnabled WRITE setCrossDeviceEnabled NOTIFY crossDeviceEnabledChanged) Q_PROPERTY(bool crossDeviceEnabled READ crossDeviceEnabled WRITE setCrossDeviceEnabled NOTIFY crossDeviceEnabledChanged)
Q_PROPERTY(AutoStartManager *autoStartManager READ autoStartManager CONSTANT) Q_PROPERTY(AutoStartManager *autoStartManager READ autoStartManager CONSTANT)
Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged) Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
Q_PROPERTY(int retryAttempts READ retryAttempts WRITE setRetryAttempts NOTIFY retryAttemptsChanged)
public: public:
AirPodsTrayApp(bool debugMode, QObject *parent = nullptr) AirPodsTrayApp(bool debugMode, QObject *parent = nullptr)
@@ -78,6 +79,7 @@ public:
// Load settings // Load settings
CrossDevice.isEnabled = loadCrossDeviceEnabled(); CrossDevice.isEnabled = loadCrossDeviceEnabled();
setEarDetectionBehavior(loadEarDetectionSettings()); setEarDetectionBehavior(loadEarDetectionSettings());
setRetryAttempts(loadRetryAttempts());
monitor->checkAlreadyConnectedDevices(); monitor->checkAlreadyConnectedDevices();
LOG_INFO("AirPodsTrayApp initialized"); LOG_INFO("AirPodsTrayApp initialized");
@@ -136,6 +138,7 @@ public:
AutoStartManager *autoStartManager() const { return m_autoStartManager; } AutoStartManager *autoStartManager() const { return m_autoStartManager; }
bool notificationsEnabled() const { return trayManager->notificationsEnabled(); } bool notificationsEnabled() const { return trayManager->notificationsEnabled(); }
void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); } void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); }
int retryAttempts() const { return m_retryAttempts; }
private: private:
bool debugMode; bool debugMode;
@@ -214,6 +217,17 @@ public slots:
emit conversationalAwarenessChanged(enabled); 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() void initiateMagicPairing()
{ {
if (!socket || !socket->isOpen()) if (!socket || !socket->isOpen())
@@ -319,6 +333,9 @@ public slots:
bool loadNotificationsEnabled() const { return m_settings->value("notifications/enabled", true).toBool(); } bool loadNotificationsEnabled() const { return m_settings->value("notifications/enabled", true).toBool(); }
void saveNotificationsEnabled(bool enabled) { m_settings->setValue("notifications/enabled", enabled); } 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: private slots:
void onTrayIconActivated() void onTrayIconActivated()
{ {
@@ -522,7 +539,7 @@ private slots:
LOG_ERROR("Socket error: " << error << ", " << localSocket->errorString()); LOG_ERROR("Socket error: " << error << ", " << localSocket->errorString());
static int retryCount = 0; static int retryCount = 0;
if (retryCount < 3) if (retryCount < m_retryAttempts)
{ {
retryCount++; retryCount++;
LOG_INFO("Retrying connection (attempt " << retryCount << ")"); LOG_INFO("Retrying connection (attempt " << retryCount << ")");
@@ -866,6 +883,7 @@ signals:
void earDetectionBehaviorChanged(int behavior); void earDetectionBehaviorChanged(int behavior);
void crossDeviceEnabledChanged(bool enabled); void crossDeviceEnabledChanged(bool enabled);
void notificationsEnabledChanged(bool enabled); void notificationsEnabledChanged(bool enabled);
void retryAttemptsChanged(int attempts);
private: private:
QBluetoothSocket *socket = nullptr; QBluetoothSocket *socket = nullptr;
@@ -878,6 +896,7 @@ private:
BluetoothMonitor *monitor; BluetoothMonitor *monitor;
QSettings *m_settings; QSettings *m_settings;
AutoStartManager *m_autoStartManager; AutoStartManager *m_autoStartManager;
int m_retryAttempts = 3;
QString m_batteryStatus; QString m_batteryStatus;
QString m_earDetectionStatus; QString m_earDetectionStatus;