2025-11-11 20:12:39 +08:00
|
|
|
|
#ifndef POWERMONITOR_H
|
|
|
|
|
|
#define POWERMONITOR_H
|
2025-11-11 15:21:39 +08:00
|
|
|
|
|
2025-11-11 20:39:04 +08:00
|
|
|
|
#include "platform/powermonitor_base.h"
|
2025-11-11 20:12:39 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 跨平台电源监视器工厂类
|
|
|
|
|
|
*
|
|
|
|
|
|
* 根据编译平台自动选择合适的电源监视器实现
|
|
|
|
|
|
* 提供统一的接口用于监听系统睡眠/唤醒事件
|
|
|
|
|
|
*/
|
|
|
|
|
|
class PowerMonitor : public PowerMonitorBase
|
2025-11-11 15:21:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2025-11-11 20:12:39 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 创建平台特定的电源监视器实例
|
|
|
|
|
|
* @param parent 父对象
|
|
|
|
|
|
*
|
|
|
|
|
|
* 根据编译时的平台宏自动创建对应的实现:
|
|
|
|
|
|
* - Linux: PowerMonitorLinux (使用 DBus login1)
|
|
|
|
|
|
* - macOS: PowerMonitorMacOS (使用 NSWorkspace 通知)
|
2025-11-11 15:21:39 +08:00
|
|
|
|
*/
|
2025-11-11 20:12:39 +08:00
|
|
|
|
explicit PowerMonitor(QObject *parent = nullptr);
|
|
|
|
|
|
~PowerMonitor() override;
|
2025-11-11 15:21:39 +08:00
|
|
|
|
|
2025-11-11 20:12:39 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 初始化电源监视器
|
|
|
|
|
|
* @return true 如果初始化成功,否则返回 false
|
2025-11-11 15:21:39 +08:00
|
|
|
|
*/
|
2025-11-11 20:12:39 +08:00
|
|
|
|
bool initialize() override;
|
2025-11-11 15:21:39 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
2025-11-11 20:12:39 +08:00
|
|
|
|
PowerMonitorBase *m_impl; // 平台特定的实现
|
2025-11-11 15:21:39 +08:00
|
|
|
|
};
|
2025-11-11 20:12:39 +08:00
|
|
|
|
|
|
|
|
|
|
#endif // POWERMONITOR_H
|