mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-02-10 19:52:24 +00:00
[Linux] Start/Stop BLE scan when going to sleep
This commit is contained in:
committed by
Tim Gromeyer
parent
05c0a7c88b
commit
fb3c8c73a4
@@ -34,6 +34,7 @@ qt_add_executable(librepods
|
|||||||
eardetection.hpp
|
eardetection.hpp
|
||||||
media/playerstatuswatcher.cpp
|
media/playerstatuswatcher.cpp
|
||||||
media/playerstatuswatcher.h
|
media/playerstatuswatcher.h
|
||||||
|
systemsleepmonitor.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
qt_add_qml_module(librepods
|
qt_add_qml_module(librepods
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ void BleManager::stopScan()
|
|||||||
discoveryAgent->stop();
|
discoveryAgent->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BleManager::isScanning() const
|
||||||
|
{
|
||||||
|
return discoveryAgent->isActive();
|
||||||
|
}
|
||||||
|
|
||||||
void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
||||||
{
|
{
|
||||||
// Check for Apple's manufacturer ID (0x004C)
|
// Check for Apple's manufacturer ID (0x004C)
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public:
|
|||||||
|
|
||||||
void startScan();
|
void startScan();
|
||||||
void stopScan();
|
void stopScan();
|
||||||
|
bool isScanning() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDeviceDiscovered(const QBluetoothDeviceInfo &info);
|
void onDeviceDiscovered(const QBluetoothDeviceInfo &info);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "ble/blemanager.h"
|
#include "ble/blemanager.h"
|
||||||
#include "ble/bleutils.h"
|
#include "ble/bleutils.h"
|
||||||
#include "QRCodeImageProvider.hpp"
|
#include "QRCodeImageProvider.hpp"
|
||||||
|
#include "systemsleepmonitor.hpp"
|
||||||
|
|
||||||
using namespace AirpodsTrayApp::Enums;
|
using namespace AirpodsTrayApp::Enums;
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ public:
|
|||||||
: QObject(parent), debugMode(debugMode), m_settings(new QSettings("AirPodsTrayApp", "AirPodsTrayApp"))
|
: QObject(parent), debugMode(debugMode), m_settings(new QSettings("AirPodsTrayApp", "AirPodsTrayApp"))
|
||||||
, m_autoStartManager(new AutoStartManager(this)), m_hideOnStart(hideOnStart), parent(parent)
|
, m_autoStartManager(new AutoStartManager(this)), m_hideOnStart(hideOnStart), parent(parent)
|
||||||
, m_deviceInfo(new DeviceInfo(this)), m_bleManager(new BleManager(this))
|
, m_deviceInfo(new DeviceInfo(this)), m_bleManager(new BleManager(this))
|
||||||
|
, m_systemSleepMonitor(new SystemSleepMonitor(this))
|
||||||
{
|
{
|
||||||
QLoggingCategory::setFilterRules(QString("airpodsApp.debug=%1").arg(debugMode ? "true" : "false"));
|
QLoggingCategory::setFilterRules(QString("airpodsApp.debug=%1").arg(debugMode ? "true" : "false"));
|
||||||
LOG_INFO("Initializing AirPodsTrayApp");
|
LOG_INFO("Initializing AirPodsTrayApp");
|
||||||
@@ -74,6 +76,8 @@ public:
|
|||||||
|
|
||||||
connect(m_bleManager, &BleManager::deviceFound, this, &AirPodsTrayApp::bleDeviceFound);
|
connect(m_bleManager, &BleManager::deviceFound, this, &AirPodsTrayApp::bleDeviceFound);
|
||||||
connect(m_deviceInfo->getBattery(), &Battery::primaryChanged, this, &AirPodsTrayApp::primaryChanged);
|
connect(m_deviceInfo->getBattery(), &Battery::primaryChanged, this, &AirPodsTrayApp::primaryChanged);
|
||||||
|
connect(m_systemSleepMonitor, &SystemSleepMonitor::systemGoingToSleep, this, &AirPodsTrayApp::onSystemGoingToSleep);
|
||||||
|
connect(m_systemSleepMonitor, &SystemSleepMonitor::systemWakingUp, this, &AirPodsTrayApp::onSystemWakingUp);
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
CrossDevice.isEnabled = loadCrossDeviceEnabled();
|
CrossDevice.isEnabled = loadCrossDeviceEnabled();
|
||||||
@@ -333,6 +337,20 @@ public slots:
|
|||||||
int loadRetryAttempts() const { return m_settings->value("bluetooth/retryAttempts", 3).toInt(); }
|
int loadRetryAttempts() const { return m_settings->value("bluetooth/retryAttempts", 3).toInt(); }
|
||||||
void saveRetryAttempts(int attempts) { m_settings->setValue("bluetooth/retryAttempts", attempts); }
|
void saveRetryAttempts(int attempts) { m_settings->setValue("bluetooth/retryAttempts", attempts); }
|
||||||
|
|
||||||
|
void onSystemGoingToSleep()
|
||||||
|
{
|
||||||
|
if (m_bleManager->isScanning())
|
||||||
|
{
|
||||||
|
LOG_INFO("Stopping BLE scan before going to sleep");
|
||||||
|
m_bleManager->stopScan();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void onSystemWakingUp()
|
||||||
|
{
|
||||||
|
LOG_INFO("System is waking up, starting ble scan");
|
||||||
|
m_bleManager->startScan();
|
||||||
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTrayIconActivated()
|
void onTrayIconActivated()
|
||||||
{
|
{
|
||||||
@@ -851,6 +869,7 @@ private:
|
|||||||
bool m_hideOnStart = false;
|
bool m_hideOnStart = false;
|
||||||
DeviceInfo *m_deviceInfo;
|
DeviceInfo *m_deviceInfo;
|
||||||
BleManager *m_bleManager;
|
BleManager *m_bleManager;
|
||||||
|
SystemSleepMonitor *m_systemSleepMonitor = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|||||||
49
linux/systemsleepmonitor.hpp
Normal file
49
linux/systemsleepmonitor.hpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#ifndef SYSTEMSLEEPMONITOR_HPP
|
||||||
|
#define SYSTEMSLEEPMONITOR_HPP
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class SystemSleepMonitor : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit SystemSleepMonitor(QObject *parent = nullptr) : QObject(parent) {
|
||||||
|
// Connect to the system D-Bus
|
||||||
|
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||||
|
if (!systemBus.isConnected()) {
|
||||||
|
qWarning() << "Cannot connect to system D-Bus";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe to PrepareForSleep signal from logind
|
||||||
|
systemBus.connect(
|
||||||
|
"org.freedesktop.login1",
|
||||||
|
"/org/freedesktop/login1",
|
||||||
|
"org.freedesktop.login1.Manager",
|
||||||
|
"PrepareForSleep",
|
||||||
|
this,
|
||||||
|
SLOT(handlePrepareForSleep(bool))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
~SystemSleepMonitor() override = default;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void systemGoingToSleep();
|
||||||
|
void systemWakingUp();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void handlePrepareForSleep(bool sleeping) {
|
||||||
|
if (sleeping) {
|
||||||
|
emit systemGoingToSleep();
|
||||||
|
} else {
|
||||||
|
emit systemWakingUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SYSTEMSLEEPMONITOR_HPP
|
||||||
Reference in New Issue
Block a user