mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:29:16 +02:00
Merge pull request #15919 from howard-stearns/mac-sleep-monitor
Mac sleep monitor
This commit is contained in:
commit
7ea8675e83
3 changed files with 89 additions and 0 deletions
|
@ -257,6 +257,10 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include "MacHelper.h"
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#include <android/log.h>
|
||||
#include "AndroidHelper.h"
|
||||
|
@ -960,6 +964,9 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
|||
DependencyManager::set<KeyboardScriptingInterface>();
|
||||
DependencyManager::set<GrabManager>();
|
||||
DependencyManager::set<AvatarPackager>();
|
||||
#ifdef Q_OS_MAC
|
||||
DependencyManager::set<MacHelper>();
|
||||
#endif
|
||||
|
||||
QString setBookmarkValue = getCmdOption(argc, constArgv, "--setBookmark");
|
||||
if (!setBookmarkValue.isEmpty()) {
|
||||
|
@ -2856,6 +2863,9 @@ Application::~Application() {
|
|||
_gameWorkload.shutdown();
|
||||
|
||||
DependencyManager::destroy<Preferences>();
|
||||
#ifdef Q_OS_MAC
|
||||
DependencyManager::destroy<MacHelper>();
|
||||
#endif
|
||||
|
||||
_entityClipboard->eraseAllOctreeElements();
|
||||
_entityClipboard.reset();
|
||||
|
|
58
interface/src/MacHelper.cpp
Executable file
58
interface/src/MacHelper.cpp
Executable file
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// MacHelper.h
|
||||
// interface/src
|
||||
//
|
||||
// Created by Howard Stearns
|
||||
// Copyright 2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "InterfaceLogging.h"
|
||||
#include "MacHelper.h"
|
||||
#include <NodeList.h>
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include <IOKit/IOMessage.h>
|
||||
#include <IOKit/pwr_mgt/IOPMLib.h>
|
||||
|
||||
// The type definitions in these variables come from IOKit, which includes a definition of Duration that conflicts with ours.
|
||||
// So... we include these definitions here rather than in the .h, as the .h is included in Application.cpp which
|
||||
// uses Duration.
|
||||
static io_connect_t root_port;
|
||||
static IONotificationPortRef notifyPortRef;
|
||||
static io_object_t notifierObject;
|
||||
static void* refCon;
|
||||
|
||||
static void sleepHandler(void* refCon, io_service_t service, natural_t messageType, void* messageArgument) {
|
||||
if (messageType == kIOMessageSystemHasPoweredOn) {
|
||||
qCInfo(interfaceapp) << "Waking up from sleep or hybernation.";
|
||||
QMetaObject::invokeMethod(DependencyManager::get<NodeList>().data(), "noteAwakening", Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
MacHelper::MacHelper() {
|
||||
#ifdef Q_OS_MAC
|
||||
root_port = IORegisterForSystemPower(refCon, ¬ifyPortRef, sleepHandler, ¬ifierObject);
|
||||
if (root_port == 0) {
|
||||
qCWarning(interfaceapp) << "IORegisterForSystemPower failed";
|
||||
return;
|
||||
}
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(),
|
||||
IONotificationPortGetRunLoopSource(notifyPortRef),
|
||||
kCFRunLoopCommonModes);
|
||||
#endif
|
||||
}
|
||||
|
||||
MacHelper::~MacHelper() {
|
||||
#ifdef Q_OS_MAC
|
||||
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
|
||||
IONotificationPortGetRunLoopSource(notifyPortRef),
|
||||
kCFRunLoopCommonModes);
|
||||
IODeregisterForSystemPower(¬ifierObject);
|
||||
IOServiceClose(root_port);
|
||||
IONotificationPortDestroy(notifyPortRef);
|
||||
#endif
|
||||
}
|
21
interface/src/MacHelper.h
Executable file
21
interface/src/MacHelper.h
Executable file
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// MacHelper.h
|
||||
// interface/src
|
||||
//
|
||||
// Created by Howard Stearns
|
||||
// Copyright 2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DependencyManager.h"
|
||||
|
||||
class MacHelper : public Dependency {
|
||||
public:
|
||||
MacHelper();
|
||||
~MacHelper();
|
||||
};
|
||||
|
Loading…
Reference in a new issue