summaryrefslogtreecommitdiffhomepage
path: root/opentrack/appnap_mac.mm
blob: 3e0bea73c05b4c212bc5acd6257c0b1d9e89f03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifdef __APPLE__

#import <Foundation/Foundation.h>

/**
 * Used to prevent macOS from throttling the opentrack process.
 */

id token = nil;

void disable_appnap_start();
void disable_appnap_stop();

void disable_appnap_start() {

    if(token){
        NSLog(@"disable_appnap_start: already started");
        return;
    }


    NSLog(@"disable_appnap_start");
    token = [[NSProcessInfo processInfo]
      beginActivityWithOptions: NSActivityUserInitiatedAllowingIdleSystemSleep
      reason: @"Disable AppNap"];
    [token retain];
}

void disable_appnap_stop() {
    if(!token){
        NSLog(@"disable_appnap_start: not started");
        return;
    }

    NSLog(@"disable_appnap_stop");
    [[NSProcessInfo processInfo] endActivity:token];
    [token release];
    token = nil;
}



#endif