我做了一个桌面通知,它每 1 分钟显示一个通知。10 秒后自行关闭。
我去吃午饭,然后电脑进入睡眠状态。当我回来时,我唤醒我的电脑,然后开始大量通知。
我该如何处理这个问题?我想如果计算机休眠它不应该显示通知。我该如何控制它?
背景.js
function show() {
var notification = webkitNotifications.createHTMLNotification(
'notification.html'
);
notification.show();
}
// Conditionally initialize the options.
if (!localStorage.isInitialized) {
localStorage.isActivated = true; // The display activation.
localStorage.frequency = 1; // The display frequency, in minutes.
localStorage.isInitialized = true; // The option initialization.
}
if (window.webkitNotifications) {
// While activated, show notifications at the display frequency.
if (JSON.parse(localStorage.isActivated)) { show(); }
var interval = 0; // The display interval, in minutes.
setInterval(function() {
interval++;
chrome.idle.queryState(15, state);
if(localStorage.frequency <= interval && state=="active")
{ show();
interval = 0;
}
}, 60000);
}