It is currently Tue Mar 31, 2020 9:02 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: App Nap
PostPosted: Thu Oct 10, 2019 4:48 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 243
Location: NL
It seems that macOS still naps an app even if it requested not too?

Code:
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...


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?


Top
 Profile  
Reply with quote  
 Post subject: Re: App Nap
PostPosted: Thu Oct 10, 2019 8:10 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2329
Location: Germany
Its only for threads, not work at MainScope

Code:
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


Procedure thWork(*Exit.Integer)
  Protected no_nap
  no_nap = BeginWork(#NSActivityUserInitiatedAllowingIdleSystemSleep)
 
  Repeat
    If *Exit\i
      Break
    EndIf
    Delay(100)
  ForEver
 
  EndWork(no_nap)
EndProcedure

w = OpenWindow(0, 0, 0, 400, 300, "Test")

Define exit
Define thread = CreateThread(@thWork(), @exit)

Repeat
  e = WaitWindowEvent()
Until e = #PB_Event_CloseWindow

exit = #True
WaitThread(thread)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: App Nap
PostPosted: Fri Oct 11, 2019 2:02 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 243
Location: NL
Good to know. And works as expected in Catalina.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye