Kodi Community Forum

Full Version: Suspend and Wake
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
i noticed that everytime i wake up my Pc (windows) from sleep mode XBMC re-scan my library. This means that exist an event that catch this situation: i need to write a very simple addon that everytime my PC wake up launches an external application (.exe).
Can someone helps me?
Isn't that a function of your operating system rather than of an application such as XBMC? It may be more fruitful to Google for a generic Windows solution. This is not an uncommon requirement (do something upon resume from sleep), so you should find plenty of hits.
For an example check the code of my addon. Below are the interesting bits:


PHP Code:
RESUME_TIMEOUT // in seconds if I recall correctly
SLEEP_TIME 1000 // milliseconds


        
resume_watchdog_time time.time()
        
# run until XBMC quits
        
while(not xbmc.abortRequested):

            if 
use_resume_watchdog:
                if (
time.time() - resume_watchdog_time) > RESUME_TIMEOUT:
                        
self.log("System resuming after suspend; logging out.")
                        
// do whatever you want to after resuming here

                
resume_watchdog_time time.time()

            if 
not xbmc.abortRequested:
                
xbmc.sleep(SLEEP_TIME)

        
self.log('Preparing to exit'

Basically what I do is keep track of time in a loop. If this loop takes longer than RESUME_TIMEOUT then I assume that the computer has been suspended for a while and just resumed. Not 100% safe (if the computer suspends again between the "if (time.time() - resume_watchdog_time) > RESUME_TIMEOUT:" and "resume_watchdog_time = time.time()" lines then you won't notice the suspended state), but good enough for me.