最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - chrome detect when computer wakes up from idle state - Stack Overflow

programmeradmin4浏览0评论

I'm making a Chrome extension that receives Chrome Google Cloud Messages. I want to detect when puter 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?

I'm making a Chrome extension that receives Chrome Google Cloud Messages. I want to detect when puter 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?

Share Improve this question edited Nov 13, 2014 at 19:54 Keven Wang asked Nov 13, 2014 at 19:42 Keven WangKeven Wang 1,2781 gold badge19 silver badges30 bronze badges 3
  • I wonder if you really need to do so. I would expect that Google manages receiving GCM for you after you've called register once. – Xan Commented Nov 13, 2014 at 19:44
  • So you want to municate this fact to your GCM server? Using GCM? – Xan Commented Nov 13, 2014 at 19:56
  • @Xan I will just do a manual fetch from my server on missed notifications. – Keven Wang Commented Nov 13, 2014 at 20:20
Add a ment  | 

2 Answers 2

Reset to default 6

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./apps/idle

You can use idle.queryState also and put a check if state === active inside query

    chrome.idle.queryState(15, function (state) {
if (state === "active"){
//Your logic
}
}
发布评论

评论列表(0)

  1. 暂无评论