@@ -17,16 +17,37 @@ let tray: ElectronTray | null = null;
17
17
const appIcon = path . join ( publicPath , "resources/tray/tray" ) ;
18
18
19
19
const iconPath = ( ) : string => {
20
- if ( process . platform === "linux" ) {
21
- return appIcon + "linux.png" ;
22
- }
20
+ switch ( process . platform ) {
21
+ case "darwin" : {
22
+ return appIcon + "macOSTemplate.png" ;
23
+ }
24
+
25
+ case "win32" : {
26
+ return appIcon + "win.ico" ;
27
+ }
23
28
24
- return (
25
- appIcon + ( process . platform === "win32" ? "win.ico" : "macOSTemplate.png" )
26
- ) ;
29
+ default : {
30
+ return appIcon + "linux.png" ;
31
+ }
32
+ }
27
33
} ;
28
34
29
- const winUnreadTrayIconPath = ( ) : string => appIcon + "unread.ico" ;
35
+ const unreadTrayIconPath = ( ) : string => {
36
+ switch ( process . platform ) {
37
+ case "darwin" : {
38
+ return appIcon + "macOSUnreadTemplate.png" ;
39
+ }
40
+
41
+ case "win32" : {
42
+ return appIcon + "unread.ico" ;
43
+ }
44
+
45
+ default : {
46
+ // Note this isn't used - see renderNativeImage()
47
+ return appIcon + "linux.png" ;
48
+ }
49
+ }
50
+ } ;
30
51
31
52
let unread = 0 ;
32
53
@@ -118,8 +139,8 @@ const renderCanvas = function (argument: number): HTMLCanvasElement {
118
139
* @return the native image
119
140
*/
120
141
const renderNativeImage = function ( argument : number ) : NativeImage {
121
- if ( process . platform === "win32" ) {
122
- return nativeImage . createFromPath ( winUnreadTrayIconPath ( ) ) ;
142
+ if ( process . platform === "win32" || process . platform === "darwin" ) {
143
+ return nativeImage . createFromPath ( unreadTrayIconPath ( ) ) ;
123
144
}
124
145
125
146
const canvas = renderCanvas ( argument ) ;
@@ -197,18 +218,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
197
218
return ;
198
219
}
199
220
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" ) {
202
- if ( argument === 0 ) {
203
- unread = argument ;
204
- tray . setImage ( iconPath ( ) ) ;
205
- tray . setToolTip ( "No unread messages" ) ;
206
- } else {
207
- unread = argument ;
208
- const image = renderNativeImage ( argument ) ;
209
- tray . setImage ( image ) ;
210
- tray . setToolTip ( `${ argument } unread messages` ) ;
211
- }
221
+ // Update tray icon based on unread count
222
+ unread = argument ;
223
+ if ( unread === 0 ) {
224
+ tray . setImage ( iconPath ( ) ) ;
225
+ tray . setToolTip ( "No unread messages" ) ;
226
+ } else {
227
+ const image = renderNativeImage ( argument ) ;
228
+ tray . setImage ( image ) ;
229
+ tray . setToolTip ( `${ argument } unread messages` ) ;
212
230
}
213
231
} ) ;
214
232
0 commit comments