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

Use setTimeout instead of setInterval to get unread count
This commit is contained in:
Yuya Ochiai
2017-08-19 00:02:39 +09:00
committed by GitHub
2 changed files with 13 additions and 2 deletions

View File

@@ -12,6 +12,10 @@ Release date: TBD
### Improvements
#### All Platforms
- Possible improvement when the app is in background state.
[#563](https://github.com/mattermost/desktop/issues/563)
#### Windows
- [Windows 7/8] Added support to open the message when clicking desktop notification.
[#67](https://github.com/mattermost/desktop/issues/67)

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;