Skip to content

Commit e8ecd56

Browse files
committed
- added support for the preferences (hide, unread, total);
- updated to v0.2.0
1 parent d7cf3ce commit e8ecd56

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

lib/main.es6

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,68 @@ import dbus from 'dbus-native';
88
export class LauncherAPIUpdater {
99
constructor(needUpdate) {
1010
this.unlisteners = [
11-
FocusedPerspectiveStore.listen(this._updateUnread, this),
12-
ThreadCountsStore.listen(this._updateUnread, this)
11+
FocusedPerspectiveStore.listen(this._updateBadges, this),
12+
ThreadCountsStore.listen(this._updateBadges, this)
1313
];
1414

15-
this._latestUnread = 0;
15+
this._onValueChanged = AppEnv.config.onDidChange('core.notifications.countBadge', ({
16+
newValue
17+
}) => {
18+
if (newValue === 'hide') {
19+
this._hideBadges();
20+
}
21+
this._updateBadges(newValue);
22+
});
1623

1724
if (needUpdate) {
18-
this._updateUnread();
25+
this._updateBadges(this._getPref());
1926
}
2027
}
2128

2229
unlisten() {
30+
this._hideBadges();
2331
for (const unlisten of this.unlisteners) {
2432
unlisten();
2533
}
34+
this._onValueChanged.dispose();
2635
}
2736

28-
_getUnread() {
29-
let unread = 0;
37+
_getStats() {
38+
let unread = 0,
39+
total = 0;
3040

3141
// unread messages depend on a focused mailbox
3242
let accountIds = FocusedPerspectiveStore.current().accountIds;
3343
for (let c of CategoryStore.getCategoriesWithRoles(accountIds, 'inbox')) {
3444
unread += ThreadCountsStore.unreadCountForCategoryId(c.id);
45+
total += ThreadCountsStore.totalCountForCategoryId(c.id);
3546
}
36-
return unread;
47+
48+
return [unread, total];
3749
}
3850

39-
_updateUnread() {
40-
let newUnread = this._getUnread();
51+
_getPref() {
52+
return AppEnv.config.get('core.notifications.countBadge');
53+
}
4154

42-
if (newUnread == this._latestUnread)
55+
_updateBadges(mode) {
56+
if (mode === undefined) {
57+
mode = this._getPref();
58+
}
59+
60+
if (mode === 'hide') {
4361
return;
62+
}
63+
64+
let [unread, total] = this._getStats();
65+
66+
let count = mode === 'unread' ? unread : total;
67+
68+
this._updateCounter(count);
69+
}
4470

45-
this._latestUnread = newUnread;
46-
this._updateCounter(newUnread);
71+
_hideBadges() {
72+
this._updateCounter(0);
4773
}
4874

4975
_updateCounter(count) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "launcher-api-support",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"main": "./lib/main",
55
"description": "Plugin for mailspring : add support for launcher api (unity)",
66
"license": "GPL-3.0",

0 commit comments

Comments
 (0)