@@ -18,16 +18,37 @@ let tray: ElectronTray | null = null;
1818const appIcon = path . join ( publicPath , "resources/tray/tray" ) ;
1919
2020const 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+ }
2429
25- return (
26- appIcon + ( process . platform === "win32" ? "win.ico" : "macOSTemplate.png" )
27- ) ;
30+ default : {
31+ return appIcon + "linux.png" ;
32+ }
33+ }
2834} ;
2935
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+ } ;
3152
3253let unread = 0 ;
3354
@@ -115,8 +136,8 @@ const renderCanvas = function (arg: number): HTMLCanvasElement {
115136 * @return the native image
116137 */
117138const 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 ( ) ) ;
120141 }
121142
122143 const canvas = renderCanvas ( arg ) ;
@@ -194,18 +215,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
194215 return ;
195216 }
196217
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` ) ;
209227 }
210228 } ) ;
211229
0 commit comments