Skip to content

Commit

Permalink
- added support for the preferences (hide, unread, total);
Browse files Browse the repository at this point in the history
- updated to v0.2.0
  • Loading branch information
ruslansin committed Nov 29, 2017
1 parent d7cf3ce commit e8ecd56
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
50 changes: 38 additions & 12 deletions lib/main.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit e8ecd56

Please sign in to comment.