Bitcoin Core  27.99.0
P2P Digital Currency
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/NSProcessInfo.h>
9 #include <Foundation/Foundation.h>
10 
12 {
13 public:
15  {
16  if(activityId)
17  enableAppNap();
18  }
19 
21  {
22  if (!activityId)
23  {
24  @autoreleasepool {
25  const NSActivityOptions activityOptions =
26  NSActivityUserInitiatedAllowingIdleSystemSleep &
27  ~(NSActivitySuddenTerminationDisabled |
28  NSActivityAutomaticTerminationDisabled);
29 
30  id processInfo = [NSProcessInfo processInfo];
31  if ([processInfo respondsToSelector:@selector(beginActivityWithOptions:reason:)])
32  {
33  activityId = [processInfo beginActivityWithOptions: activityOptions reason:@"Temporarily disable App Nap for bitcoin-qt."];
34  [activityId retain];
35  }
36  }
37  }
38  }
39 
40  void enableAppNap()
41  {
42  if(activityId)
43  {
44  @autoreleasepool {
45  id processInfo = [NSProcessInfo processInfo];
46  if ([processInfo respondsToSelector:@selector(endActivity:)])
47  [processInfo endActivity:activityId];
48 
49  [activityId release];
50  activityId = nil;
51  }
52  }
53  }
54 
55 private:
56  NSObject* activityId;
57 };
58 
60 
62 
64 {
65  impl->disableAppNap();
66 }
67 
69 {
70  impl->enableAppNap();
71 }
std::unique_ptr< CAppNapImpl > impl
Definition: macos_appnap.h:20