App Nap
Posted: Thu Oct 10, 2019 4:48 am
It seems that macOS still naps an app even if it requested not too?
ps. EndWork causes a crash in this small example, but not when put directly after BeginWork.
Any way to make it work as intended? As in no app napping as seen in activity monitor/Energy when app is in background and other app active/used?
Code: Select all
EnableExplicit
Global w, e, a
; Author : Danilo
; Date : 25.03.2014
; Link : https://www.purebasic.fr/english/viewtopic.php?f=19&t=58828
; Info : NSActivityOptions is a 64bit typedef - use it with quads (.q) !!!
#NSActivityIdleDisplaySleepDisabled = 1 << 40
#NSActivityIdleSystemSleepDisabled = 1 << 20
#NSActivitySuddenTerminationDisabled = (1 << 14)
#NSActivityAutomaticTerminationDisabled = (1 << 15)
#NSActivityUserInitiated = ($00FFFFFF | #NSActivityIdleSystemSleepDisabled)
#NSActivityUserInitiatedAllowingIdleSystemSleep = (#NSActivityUserInitiated & ~#NSActivityIdleSystemSleepDisabled)
#NSActivityBackground = $000000FF
#NSActivityLatencyCritical = $FF00000000
Procedure BeginWork(Option.q, Reason.s= "MyReason")
Protected NSProcessInfo = CocoaMessage(0,0,"NSProcessInfo processInfo")
If NSProcessInfo
ProcedureReturn CocoaMessage(0, NSProcessInfo, "beginActivityWithOptions:@", @Option, "reason:$", @Reason)
EndIf
EndProcedure
Procedure EndWork(activity)
Protected NSProcessInfo = CocoaMessage(0, 0, "NSProcessInfo processInfo")
If NSProcessInfo
CocoaMessage(0, NSProcessInfo, "endActivity:", activity)
EndIf
EndProcedure
w = OpenWindow(0, 0, 0, 400, 300, "Test")
a = BeginWork(#NSActivityUserInitiatedAllowingIdleSystemSleep, "No napping")
Debug a
Repeat
e = WaitWindowEvent()
Until e = #PB_Event_CloseWindow
EndWork(a) ;Invalid memory access...
Any way to make it work as intended? As in no app napping as seen in activity monitor/Energy when app is in background and other app active/used?