@@ -178,6 +178,30 @@ const createTray = function (): void {
178
178
}
179
179
} ;
180
180
181
+ const shouldShowTrayIcon = function ( ) : boolean {
182
+ return (
183
+ process . platform === "darwin" ||
184
+ process . platform === "win32" ||
185
+ process . platform === "linux"
186
+ ) ;
187
+ } ;
188
+
189
+ const displayTrayIcon = function ( tray : ElectronTray ) : void {
190
+ if ( process . platform === "darwin" ) {
191
+ tray . setImage ( iconPath ( ) ) ;
192
+ const showTrayBadgeCount = ConfigUtil . getConfigItem (
193
+ "trayBadgeCount" ,
194
+ false ,
195
+ ) ;
196
+ tray . setTitle ( showTrayBadgeCount && unread > 0 ? unread . toString ( ) : "" ) ;
197
+ } else {
198
+ const image = renderNativeImage ( unread ) ;
199
+ tray . setImage ( image ) ;
200
+ }
201
+
202
+ tray . setToolTip ( `${ unread } unread messages` ) ;
203
+ } ;
204
+
181
205
export function initializeTray ( serverManagerView : ServerManagerView ) {
182
206
ipcRenderer . on ( "destroytray" , ( ) => {
183
207
if ( ! tray ) {
@@ -197,17 +221,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
197
221
return ;
198
222
}
199
223
200
- // We don't want to create tray from unread messages on macOS since it already has dock badges.
201
- if ( process . platform === "linux" || process . platform === "win32" ) {
224
+ if ( shouldShowTrayIcon ( ) ) {
202
225
if ( argument === 0 ) {
203
226
unread = argument ;
204
227
tray . setImage ( iconPath ( ) ) ;
228
+ tray . setTitle ( "" ) ;
205
229
tray . setToolTip ( "No unread messages" ) ;
206
230
} else {
207
231
unread = argument ;
208
- const image = renderNativeImage ( argument ) ;
209
- tray . setImage ( image ) ;
210
- tray . setToolTip ( `${ argument } unread messages` ) ;
232
+ displayTrayIcon ( tray ) ;
211
233
}
212
234
}
213
235
} ) ;
@@ -225,10 +247,8 @@ export function initializeTray(serverManagerView: ServerManagerView) {
225
247
} else {
226
248
state = true ;
227
249
createTray ( ) ;
228
- if ( process . platform === "linux" || process . platform === "win32" ) {
229
- const image = renderNativeImage ( unread ) ;
230
- tray ! . setImage ( image ) ;
231
- tray ! . setToolTip ( `${ unread } unread messages` ) ;
250
+ if ( shouldShowTrayIcon ( ) ) {
251
+ displayTrayIcon ( tray ! ) ;
232
252
}
233
253
234
254
ConfigUtil . setConfigItem ( "trayIcon" , true ) ;
@@ -239,6 +259,12 @@ export function initializeTray(serverManagerView: ServerManagerView) {
239
259
240
260
ipcRenderer . on ( "toggletray" , toggleTray ) ;
241
261
262
+ ipcRenderer . on ( "toggle-tray-badge-count" , ( ) => {
263
+ if ( tray && shouldShowTrayIcon ( ) ) {
264
+ displayTrayIcon ( tray ) ;
265
+ }
266
+ } ) ;
267
+
242
268
if ( ConfigUtil . getConfigItem ( "trayIcon" , true ) ) {
243
269
createTray ( ) ;
244
270
}
0 commit comments