Bitcoin ABC  0.22.13
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/Foundation.h>
9 #include <Foundation/NSProcessInfo.h>
10 
12 public:
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 
59 
61 
63  impl->disableAppNap();
64 }
65 
67  impl->enableAppNap();
68 }
std::unique_ptr< CAppNapImpl > impl
Definition: macos_appnap.h:19