@@ -18,16 +18,37 @@ let tray: ElectronTray | null = null;
18
18
const appIcon = path . join ( publicPath , "resources/tray/tray" ) ;
19
19
20
20
const iconPath = ( ) : string => {
21
- if ( process . platform === "linux" ) {
22
- return appIcon + "linux.png" ;
23
- }
21
+ switch ( process . platform ) {
22
+ case "darwin" : {
23
+ return appIcon + "macOSTemplate.png" ;
24
+ }
25
+
26
+ case "win32" : {
27
+ return appIcon + "win.ico" ;
28
+ }
24
29
25
- return (
26
- appIcon + ( process . platform === "win32" ? "win.ico" : "macOSTemplate.png" )
27
- ) ;
30
+ default : {
31
+ return appIcon + "linux.png" ;
32
+ }
33
+ }
28
34
} ;
29
35
30
- const winUnreadTrayIconPath = ( ) : string => appIcon + "unread.ico" ;
36
+ const unreadTrayIconPath = ( ) : string => {
37
+ switch ( process . platform ) {
38
+ case "darwin" : {
39
+ return appIcon + "macOSUnreadTemplate.png" ;
40
+ }
41
+
42
+ case "win32" : {
43
+ return appIcon + "unread.ico" ;
44
+ }
45
+
46
+ default : {
47
+ // Note this isn't used - see renderNativeImage()
48
+ return appIcon + "linux.png" ;
49
+ }
50
+ }
51
+ } ;
31
52
32
53
let unread = 0 ;
33
54
@@ -115,8 +136,8 @@ const renderCanvas = function (arg: number): HTMLCanvasElement {
115
136
* @return the native image
116
137
*/
117
138
const renderNativeImage = function ( arg : number ) : NativeImage {
118
- if ( process . platform === "win32" ) {
119
- return nativeImage . createFromPath ( winUnreadTrayIconPath ( ) ) ;
139
+ if ( process . platform === "win32" || process . platform === "darwin" ) {
140
+ return nativeImage . createFromPath ( unreadTrayIconPath ( ) ) ;
120
141
}
121
142
122
143
const canvas = renderCanvas ( arg ) ;
@@ -194,18 +215,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
194
215
return ;
195
216
}
196
217
197
- // We don't want to create tray from unread messages on macOS since it already has dock badges.
198
- if ( process . platform === "linux" || process . platform === "win32" ) {
199
- if ( arg === 0 ) {
200
- unread = arg ;
201
- tray . setImage ( iconPath ( ) ) ;
202
- tray . setToolTip ( "No unread messages" ) ;
203
- } else {
204
- unread = arg ;
205
- const image = renderNativeImage ( arg ) ;
206
- tray . setImage ( image ) ;
207
- tray . setToolTip ( `${ arg } unread messages` ) ;
208
- }
218
+ // Update tray icon based on unread count
219
+ unread = arg ;
220
+ if ( unread === 0 ) {
221
+ tray . setImage ( iconPath ( ) ) ;
222
+ tray . setToolTip ( "No unread messages" ) ;
223
+ } else {
224
+ const image = renderNativeImage ( arg ) ;
225
+ tray . setImage ( image ) ;
226
+ tray . setToolTip ( `${ arg } unread messages` ) ;
209
227
}
210
228
} ) ;
211
229
0 commit comments