Skip to content

Commit 88c2312

Browse files
committed
Create NSProcessInfoUtils.java
A sample by Remi Cartier showing how to interface with NSProcessInfo to solve the appnap problem.
1 parent 8310d1d commit 88c2312

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import ca.weblite.objc.Client;
2+
import ca.weblite.objc.Proxy;
3+
4+
/**
5+
* Created by IntelliJ IDEA.
6+
* User: remicartier (remi.cartier@gmail.com)
7+
* Date: 2014-08-06
8+
* Time: 8:13 PM
9+
*/
10+
public class NSProcessInfoUtils {
11+
12+
private final static long NSActivityUserInitiated = (0x00FFFFFFL | (1L << 20));
13+
14+
/**
15+
* To ensure Mac OS X doesn't slow down your app because of App Nap, call this method
16+
* @param reason the reason for allowing the app to work at full speed
17+
* @return the activity id as a Proxy object
18+
*/
19+
public static Proxy beginActivityWithOptions(String reason) {
20+
21+
Client c = Client.getInstance();
22+
Proxy processInfo = c.sendProxy("NSProcessInfo", "processInfo");
23+
return processInfo.sendProxy("beginActivityWithOptions:reason:", NSActivityUserInitiated, reason);
24+
}
25+
26+
/**
27+
* When the activity is finished, to re-enable app napping call this method
28+
* @param activity previously returned by beginActivityWithOptions()
29+
*/
30+
public static void endActivity(Proxy activity) {
31+
32+
if (activity != null) {
33+
Client c = Client.getInstance();
34+
Proxy processInfo = c.sendProxy("NSProcessInfo", "processInfo");
35+
processInfo.send("endActivity:", activity);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)