ea8569e97b
* Merge #12783: macOS: disable AppNap during sync 1e0f3c44992fb82e6bf36c2ef9277b0759c17c4c macOS: disable AppNap during sync (Alexey Ivanov) Pull request description: Code based on pull/5804. Tested only on macOS 10.13.3 and should support 10.9+. What macOS versions bitcoin core currently supports? Tree-SHA512: 85809b8d8d8a05169437b4268988da0b7372c29c6da3223ebdc106dc16dcb6d3caa5c52ace3591467005b50a63fd8b2ab1cb071cb4f450032932df25d5063315 * Refactor * Drop `#include <memory>` from `src/qt/bitcoingui.h` Was included by mistake.
72 lines
1.8 KiB
Plaintext
72 lines
1.8 KiB
Plaintext
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include "macos_appnap.h"
|
|
|
|
#include <AvailabilityMacros.h>
|
|
#include <Foundation/NSProcessInfo.h>
|
|
#include <Foundation/Foundation.h>
|
|
|
|
class CAppNapInhibitor::CAppNapImpl
|
|
{
|
|
public:
|
|
~CAppNapImpl()
|
|
{
|
|
if(activityId)
|
|
enableAppNap();
|
|
}
|
|
|
|
void disableAppNap()
|
|
{
|
|
if (!activityId)
|
|
{
|
|
@autoreleasepool {
|
|
const NSActivityOptions activityOptions =
|
|
NSActivityUserInitiatedAllowingIdleSystemSleep &
|
|
~(NSActivitySuddenTerminationDisabled |
|
|
NSActivityAutomaticTerminationDisabled);
|
|
|
|
id processInfo = [NSProcessInfo processInfo];
|
|
if ([processInfo respondsToSelector:@selector(beginActivityWithOptions:reason:)])
|
|
{
|
|
activityId = [processInfo beginActivityWithOptions: activityOptions reason:@"Temporarily disable App Nap for dash-qt."];
|
|
[activityId retain];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void enableAppNap()
|
|
{
|
|
if(activityId)
|
|
{
|
|
@autoreleasepool {
|
|
id processInfo = [NSProcessInfo processInfo];
|
|
if ([processInfo respondsToSelector:@selector(endActivity:)])
|
|
[processInfo endActivity:activityId];
|
|
|
|
[activityId release];
|
|
activityId = nil;
|
|
}
|
|
}
|
|
}
|
|
|
|
private:
|
|
NSObject* activityId;
|
|
};
|
|
|
|
CAppNapInhibitor::CAppNapInhibitor() : impl(new CAppNapImpl()) {}
|
|
|
|
CAppNapInhibitor::~CAppNapInhibitor() = default;
|
|
|
|
void CAppNapInhibitor::disableAppNap()
|
|
{
|
|
impl->disableAppNap();
|
|
}
|
|
|
|
void CAppNapInhibitor::enableAppNap()
|
|
{
|
|
impl->enableAppNap();
|
|
}
|