fix(badge): Add option for total count

This commit is contained in:
Jackie Luo 2016-06-01 11:42:21 -07:00
parent 2f7d64b27a
commit 58e1ed57ee
2 changed files with 14 additions and 11 deletions

View file

@ -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']

View file

@ -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("");
}