@@ -17,16 +17,37 @@ let tray: ElectronTray | null = null;
1717const appIcon = path . join ( publicPath , "resources/tray/tray" ) ;
1818
1919const 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+ }
2328
24- return (
25- appIcon + ( process . platform === "win32" ? "win.ico" : "macOSTemplate.png" )
26- ) ;
29+ default : {
30+ return appIcon + "linux.png" ;
31+ }
32+ }
2733} ;
2834
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+ } ;
3051
3152let unread = 0 ;
3253
@@ -118,8 +139,8 @@ const renderCanvas = function (argument: number): HTMLCanvasElement {
118139 * @return the native image
119140 */
120141const 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 ( ) ) ;
123144 }
124145
125146 const canvas = renderCanvas ( argument ) ;
@@ -197,18 +218,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
197218 return ;
198219 }
199220
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` ) ;
212230 }
213231 } ) ;
214232
0 commit comments