Bitcoin ABC
0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
src
qt
macos_appnap.mm
Go to the documentation of this file.
1
// Copyright (c) 2011-2018 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include "
macos_appnap.h
"
6
7
#include <AvailabilityMacros.h>
8
#include <Foundation/Foundation.h>
9
#include <Foundation/NSProcessInfo.h>
10
11
class
CAppNapInhibitor::CAppNapImpl
{
12
public
:
13
~CAppNapImpl
() {
14
if
(
activityId
) {
15
enableAppNap
();
16
}
17
}
18
19
void
disableAppNap
() {
20
if
(!
activityId
) {
21
@
autoreleasepool
{
22
const
NSActivityOptions
activityOptions
=
23
NSActivityUserInitiatedAllowingIdleSystemSleep
&
24
~(
NSActivitySuddenTerminationDisabled
|
25
NSActivityAutomaticTerminationDisabled
);
26
27
id
processInfo
= [
NSProcessInfo
processInfo
];
28
if
([
processInfo
respondsToSelector
:
@selector
29
(
beginActivityWithOptions
:reason:)]) {
30
activityId
= [
processInfo
31
beginActivityWithOptions
:
activityOptions
32
reason:
@"Temporarily disable App Nap "
33
@"for bitcoin-qt."
];
34
[
activityId
retain
];
35
}
36
}
37
}
38
}
39
40
void
enableAppNap
() {
41
if
(
activityId
) {
42
@
autoreleasepool
{
43
id
processInfo
= [
NSProcessInfo
processInfo
];
44
if
([
processInfo
respondsToSelector
:
@selector
(
endActivity
:)]) {
45
[
processInfo
endActivity
:
activityId
];
46
}
47
48
[
activityId
release];
49
activityId
=
nil
;
50
}
51
}
52
}
53
54
private
:
55
NSObject
*
activityId
;
56
};
57
58
CAppNapInhibitor::CAppNapInhibitor
() : impl(
new
CAppNapImpl
()) {}
59
60
CAppNapInhibitor::~CAppNapInhibitor
() =
default
;
61
62
void
CAppNapInhibitor::disableAppNap
() {
63
impl
->disableAppNap();
64
}
65
66
void
CAppNapInhibitor::enableAppNap
() {
67
impl
->enableAppNap();
68
}
CAppNapInhibitor::CAppNapImpl
Definition
macos_appnap.mm:11
CAppNapInhibitor::CAppNapImpl::disableAppNap
void disableAppNap()
Definition
macos_appnap.mm:19
CAppNapInhibitor::CAppNapImpl::enableAppNap
void enableAppNap()
Definition
macos_appnap.mm:40
CAppNapInhibitor::CAppNapImpl::activityId
NSObject * activityId
Definition
macos_appnap.mm:55
CAppNapInhibitor::CAppNapImpl::~CAppNapImpl
~CAppNapImpl()
Definition
macos_appnap.mm:13
CAppNapInhibitor::disableAppNap
void disableAppNap()
Definition
macos_appnap.mm:62
CAppNapInhibitor::CAppNapInhibitor
CAppNapInhibitor()
Definition
macos_appnap.mm:58
CAppNapInhibitor::enableAppNap
void enableAppNap()
Definition
macos_appnap.mm:66
CAppNapInhibitor::impl
std::unique_ptr< CAppNapImpl > impl
Definition
macos_appnap.h:20
CAppNapInhibitor::~CAppNapInhibitor
~CAppNapInhibitor()
macos_appnap.h
GetRand
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition
random.h:85
Generated on Thu Dec 26 2024 02:38:03 for Bitcoin ABC by
1.9.8