Merge pull request #576 from yuya-oc/unread-count-interval

Use setTimeout instead of setInterval to get unread count
This commit is contained in:
Yuya Ochiai 2017-08-28 21:19:20 +09:00 committed by GitHub
commit 4c3e5d3590

View file

@ -5,6 +5,8 @@ const ipc = electron.ipcRenderer;
const webFrame = electron.webFrame; const webFrame = electron.webFrame;
const notification = require('../js/notification'); const notification = require('../js/notification');
const UNREAD_COUNT_INTERVAL = 1000;
Reflect.deleteProperty(global.Buffer); // http://electron.atom.io/docs/tutorial/security/#buffer-global Reflect.deleteProperty(global.Buffer); // http://electron.atom.io/docs/tutorial/security/#buffer-global
function hasClass(element, className) { function hasClass(element, className) {
@ -15,7 +17,7 @@ function hasClass(element, className) {
return false; return false;
} }
setInterval(function getUnreadCount() { function getUnreadCount() {
if (!this.unreadCount) { if (!this.unreadCount) {
this.unreadCount = 0; this.unreadCount = 0;
} }
@ -28,6 +30,7 @@ setInterval(function getUnreadCount() {
ipc.sendToHost('onUnreadCountChange', 0, 0, false, false); ipc.sendToHost('onUnreadCountChange', 0, 0, false, false);
this.unreadCount = 0; this.unreadCount = 0;
this.mentionCount = 0; this.mentionCount = 0;
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
return; return;
} }
@ -61,6 +64,7 @@ setInterval(function getUnreadCount() {
// find active post-list. // find active post-list.
var postLists = document.querySelectorAll('div.post-list__content'); var postLists = document.querySelectorAll('div.post-list__content');
if (postLists.length === 0) { if (postLists.length === 0) {
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
return; return;
} }
var post = null; var post = null;
@ -70,6 +74,7 @@ setInterval(function getUnreadCount() {
} }
} }
if (post === null) { if (post === null) {
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
return; return;
} }
@ -111,7 +116,9 @@ setInterval(function getUnreadCount() {
} }
this.unreadCount = unreadCount; this.unreadCount = unreadCount;
this.mentionCount = mentionCount; this.mentionCount = mentionCount;
}, 1000); setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
}
setTimeout(getUnreadCount, UNREAD_COUNT_INTERVAL);
function isElementVisible(elem) { function isElementVisible(elem) {
return elem.offsetHeight !== 0; return elem.offsetHeight !== 0;