mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-02-11 20:18:59 +00:00
[Linux] Start/Stop BLE scan when going to sleep
This commit is contained in:
committed by
Tim Gromeyer
parent
05c0a7c88b
commit
fb3c8c73a4
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