Use setTimeout instead of setInterval to get unread count

This commit is contained in:
Yuya Ochiai
2017-07-21 00:09:15 +09:00
parent aad60e2d16
commit de29dfab46

View File

@@ -5,6 +5,8 @@ const ipc = electron.ipcRenderer;
const webFrame = electron.webFrame;
const EnhancedNotification = require('../js/notification');
const UNREAD_COUNT_INTERVAL = 1000;
Notification = EnhancedNotification; // eslint-disable-line no-global-assign, no-native-reassign
Reflect.deleteProperty(global.Buffer); // http://electron.atom.io/docs/tutorial/security/#buffer-global
@@ -17,7 +19,7 @@ function hasClass(element, className) {
return false;
}
setInterval(function getUnreadCount() {
function getUnreadCount() {
if (!this.unreadCount) {
this.unreadCount = 0;
}
@@ -30,6 +32,7 @@ setInterval(function getUnreadCount() {
ipc.sendToHost('onUnreadCountChange', 0, 0, false, false);
this.unreadCount = 0;
this.mentionCount = 0;
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
return;
}
@@ -63,6 +66,7 @@ setInterval(function getUnreadCount() {
// find active post-list.
var postLists = document.querySelectorAll('div.post-list__content');
if (postLists.length === 0) {
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
return;
}
var post = null;
@@ -72,6 +76,7 @@ setInterval(function getUnreadCount() {
}
}
if (post === null) {
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
return;
}
@@ -113,7 +118,9 @@ setInterval(function getUnreadCount() {
}
this.unreadCount = unreadCount;
this.mentionCount = mentionCount;
}, 1000);
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
}
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
function isElementVisible(elem) {
return elem.offsetHeight !== 0;