@@ -8,42 +8,68 @@ import dbus from 'dbus-native';
8
8
export class LauncherAPIUpdater {
9
9
constructor ( needUpdate ) {
10
10
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 )
13
13
] ;
14
14
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
+ } ) ;
16
23
17
24
if ( needUpdate ) {
18
- this . _updateUnread ( ) ;
25
+ this . _updateBadges ( this . _getPref ( ) ) ;
19
26
}
20
27
}
21
28
22
29
unlisten ( ) {
30
+ this . _hideBadges ( ) ;
23
31
for ( const unlisten of this . unlisteners ) {
24
32
unlisten ( ) ;
25
33
}
34
+ this . _onValueChanged . dispose ( ) ;
26
35
}
27
36
28
- _getUnread ( ) {
29
- let unread = 0 ;
37
+ _getStats ( ) {
38
+ let unread = 0 ,
39
+ total = 0 ;
30
40
31
41
// unread messages depend on a focused mailbox
32
42
let accountIds = FocusedPerspectiveStore . current ( ) . accountIds ;
33
43
for ( let c of CategoryStore . getCategoriesWithRoles ( accountIds , 'inbox' ) ) {
34
44
unread += ThreadCountsStore . unreadCountForCategoryId ( c . id ) ;
45
+ total += ThreadCountsStore . totalCountForCategoryId ( c . id ) ;
35
46
}
36
- return unread ;
47
+
48
+ return [ unread , total ] ;
37
49
}
38
50
39
- _updateUnread ( ) {
40
- let newUnread = this . _getUnread ( ) ;
51
+ _getPref ( ) {
52
+ return AppEnv . config . get ( 'core.notifications.countBadge' ) ;
53
+ }
41
54
42
- if ( newUnread == this . _latestUnread )
55
+ _updateBadges ( mode ) {
56
+ if ( mode === undefined ) {
57
+ mode = this . _getPref ( ) ;
58
+ }
59
+
60
+ if ( mode === 'hide' ) {
43
61
return ;
62
+ }
63
+
64
+ let [ unread , total ] = this . _getStats ( ) ;
65
+
66
+ let count = mode === 'unread' ? unread : total ;
67
+
68
+ this . _updateCounter ( count ) ;
69
+ }
44
70
45
- this . _latestUnread = newUnread ;
46
- this . _updateCounter ( newUnread ) ;
71
+ _hideBadges ( ) {
72
+ this . _updateCounter ( 0 ) ;
47
73
}
48
74
49
75
_updateCounter ( count ) {
0 commit comments