baragona / Brightness

Sync macbook screen brightness to non-Apple external display.
Artistic License 2.0
79 stars 11 forks source link

Prevent from sleeping #8

Open arpachain-admin opened 5 years ago

arpachain-admin commented 5 years ago

My MBP13 2018 consumes a lot of power overnight. And especially when I am travelling, the power get completely drain. This is really annoying. So I did some search and found this command: pmset -g assertions Then I got this result:

Assertion status system-wide: BackgroundTask 0 ApplePushServiceTask 0 UserIsActive 1 PreventUserIdleDisplaySleep 0 PreventSystemSleep 0 ExternalMedia 0 PreventUserIdleSystemSleep 1 NetworkClientActive 0 Listed by owning process: pid 87941(Brightness): [0x0005897d00018c7a] 00:02:40 PreventUserIdleSystemSleep named: "Prevent app nap from pausing brightness sync." pid 110(hidd): [0x00057319000988f2] 00:00:00 UserIsActive named: "com.apple.iohideventsystem.queue.tickle.4295505597.3" Timeout will fire in 1800 secs Action=TimeoutActionRelease

It seems that brightness app has been preventing the mac from sleeping.

Can you fix?

baragona commented 5 years ago

App nap is disabled on this app because it macOS will pause the app and make its timers run very very slowly otherwise.

I wasn't aware that this actually prevents the computer from sleeping. Are you sure this is the case? I am not too familiar with this.

Can you think of any work arounds that will allows the computer to sleep while not affecting the performance of this app?

callzhang commented 4 years ago

I have the similar problem. I am not familiar with MacOS development, but the following thoughts may help you:

  1. Enable App nap and listen to system event described. The system should wake the app up. (at least in iOS it will)
  2. Listen to system event about "lid close", enable app nap then. And vise versa.
  3. Dig more about the reason that prevent the system from sleeping - is it really the app nap option?