From 58e1ed57ee2397d1067738b2d87774987bc4474d Mon Sep 17 00:00:00 2001 From: Jackie Luo Date: Wed, 1 Jun 2016 11:42:21 -0700 Subject: [PATCH] fix(badge): Add option for total count --- src/config-schema.coffee | 9 +++++---- src/flux/stores/badge-store.es6 | 16 +++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/config-schema.coffee b/src/config-schema.coffee index 25a2faa09..f70a5ba78 100644 --- a/src/config-schema.coffee +++ b/src/config-schema.coffee @@ -96,8 +96,9 @@ module.exports = type: 'boolean' default: true title: "Play sound when receiving new mail" - unreadBadge: - type: 'boolean' - default: true + countBadge: + type: 'string' + default: 'unread' + enum: ['hide', 'unread', 'total'] + enumLabels: ['Hide Badge', 'Show Unread Count', 'Show Total Count'] title: "Show badge on the app icon" - platforms: ['darwin'] diff --git a/src/flux/stores/badge-store.es6 b/src/flux/stores/badge-store.es6 index 0b773f743..1f48e43b5 100644 --- a/src/flux/stores/badge-store.es6 +++ b/src/flux/stores/badge-store.es6 @@ -12,9 +12,9 @@ class BadgeStore extends NylasStore { this.listenTo(FocusedPerspectiveStore, this._updateCounts); this.listenTo(ThreadCountsStore, this._updateCounts); - NylasEnv.config.onDidChange('core.notifications.unreadBadge', ({newValue}) => { - if (newValue === true) { - this._setBadgeForCount() + NylasEnv.config.onDidChange('core.notifications.countBadge', ({newValue}) => { + if (newValue !== 'hide') { + this._setBadgeForCount(); } else { this._setBadge(""); } @@ -52,17 +52,19 @@ class BadgeStore extends NylasStore { } _setBadgeForCount = () => { - if (!NylasEnv.config.get('core.notifications.unreadBadge')) { + const badgePref = NylasEnv.config.get('core.notifications.countBadge'); + if (!badgePref || badgePref === 'hide') { return; } if (!NylasEnv.isMainWindow() && !NylasEnv.inSpecMode()) { return; } - if (this._unread > 999) { + const count = badgePref === 'unread' ? this._unread : this._total; + if (count > 999) { this._setBadge("999+"); - } else if (this._unread > 0) { - this._setBadge(`${this._unread}`); + } else if (count > 0) { + this._setBadge(`${count}`); } else { this._setBadge(""); }