Sunday, December 24, 2017

App Nap in High Sierra

Update: 1/5/2018 It turns out this problem had nothing to do with app nap at all. It’s a thread contention issue in the screen drawing code in High Sierra and there is a very nasty workaround you can do to get it working. I’ve written about it Here


There is an undocumented change to how App Nap is handled in the latest build of the High Sierra operating system. In past OS versions the operating system actually believed you when you said you were executing a user initiated process and let your app continue to operate as normal even when the user wasn’t using your app. That seems no longer to be the case with High Sierra.

App Nap is a great idea overall. If your app isn’t being used it can be put to sleep and we can not waste the battery or the power to keep it doing all it’s interface animation and what now while the user isn’t using it. Unfortunately apps like my day job at XTension need to remain responsive to incoming data or connections even when the user has been absent for months. In the past this was no problem! MacOS was efficient and my app managed it’s memory carefully and didn’t leak and so for 6 months or more you could run in the background and keep doing all you needed to do.

That is no longer the case with High Sierra. If the user isn’t there and the screen goes to sleep then ALL the user apps will go to sleep. Even if they have done what apple suggested and register a “user initiated action” that should continue to work even while the user wanders off. High Sierra seems to decide that if the user has let the screen go to sleep then no user tasks need to be of high priority. This is remarkably frustrating as there are definitely apps that want to run while there is no user sitting at the machine.

The officially documented way to disable app nap does NOT work with High Sierra.

The only work around that I’ve been able to figure out is to disable putting the screen sleep. You can do this manually in the energy saver preferences just set the screen to never go to sleep. If you’re doing the official apple way of doing things then you can set the disable Idle Screen Sleep flag when you create your action.

Or you can just tell your users to set their energy saver preferences to never shut off the screen... This is a completely undocumented change that makes a huge difference to us developers of apps that run without the user sitting in front of the machine. I am very frustrated.
.code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; max-height: 200px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; }