Open sreilly opened 9 years ago
Oops, submitted this anonymously. Commenting to get follow-up emails.
This sounds like an enhancement request. Would anyone like to contribute the objective-C code to make it work?
Adding this to main.m (just above the call to jli_LaunchFxnPtr) seems to have disabled app nap successfully.
// Attempt to prevent app nap from slowing us down
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)])
[[NSProcessInfo processInfo] beginActivityWithOptions:0x00FFFFFF reason:@"Can't have App Nap"];
// Invoke JLI_Launch()
It would be nice to have a setting in the config file to turn this on or off, but I'm not sufficiently familiar with how the settings work do add that. Perhaps someone else can add a setting to control this feature.
-JM
Original report by Anonymous.
App Nap (introduced in Mavericks) has been making my Java app sluggish. It's a real-time music app, so it needs to be responsive. However, OS X decides - after a couple minutes of it being in the background - that it is not doing anything and should be put to sleep: aka the dreaded App Nap. This causes threads to wake up later than they are supposed to and ultimately the music notes lag or the USB device disconnects incorrectly.
There are a couple of hacks around it, for instance:
Hack 1
Putting
in the PList, however that makes your app truly run in the background and removes your dock icon.
Hack 2
Another hack is to run this terminal command every time you start the app:
That is also rather hacky, and there are reports of it not working.
Proper Way
The recommended, Apple way of disabling App Nap is in code, like this example:
Is there a way we can add an option to the build file that runs this method in the launcher? It also needs to run the
endActivity
method after the app exits. This is the part I'm not sure about: doesJLI_Launch()
return once the app exits, or does it return immediately?