diff --git a/lib/main.es6 b/lib/main.es6 index 4372e29..f56d642 100644 --- a/lib/main.es6 +++ b/lib/main.es6 @@ -8,42 +8,68 @@ import dbus from 'dbus-native'; export class LauncherAPIUpdater { constructor(needUpdate) { this.unlisteners = [ - FocusedPerspectiveStore.listen(this._updateUnread, this), - ThreadCountsStore.listen(this._updateUnread, this) + FocusedPerspectiveStore.listen(this._updateBadges, this), + ThreadCountsStore.listen(this._updateBadges, this) ]; - this._latestUnread = 0; + this._onValueChanged = AppEnv.config.onDidChange('core.notifications.countBadge', ({ + newValue + }) => { + if (newValue === 'hide') { + this._hideBadges(); + } + this._updateBadges(newValue); + }); if (needUpdate) { - this._updateUnread(); + this._updateBadges(this._getPref()); } } unlisten() { + this._hideBadges(); for (const unlisten of this.unlisteners) { unlisten(); } + this._onValueChanged.dispose(); } - _getUnread() { - let unread = 0; + _getStats() { + let unread = 0, + total = 0; // unread messages depend on a focused mailbox let accountIds = FocusedPerspectiveStore.current().accountIds; for (let c of CategoryStore.getCategoriesWithRoles(accountIds, 'inbox')) { unread += ThreadCountsStore.unreadCountForCategoryId(c.id); + total += ThreadCountsStore.totalCountForCategoryId(c.id); } - return unread; + + return [unread, total]; } - _updateUnread() { - let newUnread = this._getUnread(); + _getPref() { + return AppEnv.config.get('core.notifications.countBadge'); + } - if (newUnread == this._latestUnread) + _updateBadges(mode) { + if (mode === undefined) { + mode = this._getPref(); + } + + if (mode === 'hide') { return; + } + + let [unread, total] = this._getStats(); + + let count = mode === 'unread' ? unread : total; + + this._updateCounter(count); + } - this._latestUnread = newUnread; - this._updateCounter(newUnread); + _hideBadges() { + this._updateCounter(0); } _updateCounter(count) { diff --git a/package.json b/package.json index 0dbdef0..477992c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "launcher-api-support", - "version": "0.1.0", + "version": "0.2.0", "main": "./lib/main", "description": "Plugin for mailspring : add support for launcher api (unity)", "license": "GPL-3.0",