[Linux] Add ear detection behavior setting

This commit is contained in:
Tim Gromeyer
2025-04-18 22:56:14 +02:00
committed by Tim Gromeyer
parent 3aeff4d986
commit 816992fd8a
2 changed files with 43 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ class AirPodsTrayApp : public QObject {
Q_PROPERTY(bool leftPodInEar READ isLeftPodInEar NOTIFY primaryChanged)
Q_PROPERTY(bool rightPodInEar READ isRightPodInEar NOTIFY primaryChanged)
Q_PROPERTY(bool airpodsConnected READ areAirpodsConnected NOTIFY airPodsStatusChanged)
Q_PROPERTY(int earDetectionBehavior READ earDetectionBehavior WRITE setEarDetectionBehavior NOTIFY earDetectionBehaviorChanged)
public:
AirPodsTrayApp(bool debugMode)
@@ -64,7 +65,9 @@ public:
connect(m_battery, &Battery::primaryChanged, this, &AirPodsTrayApp::primaryChanged);
// Load settings
CrossDevice.isEnabled = loadCrossDeviceEnabled();
setEarDetectionBehavior(loadEarDetectionSettings());
monitor->checkAlreadyConnectedDevices();
LOG_INFO("AirPodsTrayApp initialized");
@@ -120,6 +123,8 @@ public:
}
}
bool areAirpodsConnected() const { return socket && socket->isOpen() && socket->state() == QBluetoothSocket::SocketState::ConnectedState; }
int earDetectionBehavior() const { return mediaController->getEarDetectionBehavior(); }
bool crossDeviceEnabled() const { return CrossDevice.isEnabled; }
private:
bool debugMode;
@@ -252,6 +257,19 @@ public slots:
}
}
void setEarDetectionBehavior(int behavior)
{
if (behavior == earDetectionBehavior())
{
LOG_INFO("Ear detection behavior is already set to: " << behavior);
return;
}
mediaController->setEarDetectionBehavior(static_cast<MediaController::EarDetectionBehavior>(behavior));
saveEarDetectionSettings();
emit earDetectionBehaviorChanged(behavior);
}
bool writePacketToSocket(const QByteArray &packet, const QString &logMessage)
{
if (socket && socket->isOpen())
@@ -819,9 +837,10 @@ signals:
void modelChanged();
void primaryChanged();
void airPodsStatusChanged();
void earDetectionBehaviorChanged(int behavior);
void crossDeviceEnabledChanged(bool enabled);
private:
QSystemTrayIcon *trayIcon;
private : QSystemTrayIcon *trayIcon;
QMenu *trayMenu;
QBluetoothSocket *socket = nullptr;
QBluetoothSocket *phoneSocket = nullptr;