Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome detect when computer wakes up from idle state

I'm making a Chrome extension that receives Chrome Google Cloud Messages. I want to detect when computer wakes up from sleep/reconnects to internet, so that my application can start receiving messages again. For my specific case, I don't want GCM to throttle the pushes, so I set the ttl to 0, which is deliver now or never. (user device will never receive message while idle.)

In javascript, how do I detect when Chrome browser recovers from idle state?

More specifically, how could I do it in Chrome extension using chrome. api calls?

like image 737
Keven Wang Avatar asked Nov 13 '14 19:11

Keven Wang


1 Answers

Chrome has an idle API:

chrome.idle.onStateChanged(function(state) {
    if (state == 'active') {
        console.log('State is now active');
    }
});

You can read about it here: https://developer.chrome.com/apps/idle

like image 164
donaddon Avatar answered Oct 18 '22 03:10

donaddon