[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
}
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

View File

@@ -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;