@@ -178,6 +178,30 @@ const createTray = function (): void {
178178 }
179179} ;
180180
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+
181205export function initializeTray ( serverManagerView : ServerManagerView ) {
182206 ipcRenderer . on ( "destroytray" , ( ) => {
183207 if ( ! tray ) {
@@ -197,17 +221,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
197221 return ;
198222 }
199223
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 ( ) ) {
202225 if ( argument === 0 ) {
203226 unread = argument ;
204227 tray . setImage ( iconPath ( ) ) ;
228+ tray . setTitle ( "" ) ;
205229 tray . setToolTip ( "No unread messages" ) ;
206230 } else {
207231 unread = argument ;
208- const image = renderNativeImage ( argument ) ;
209- tray . setImage ( image ) ;
210- tray . setToolTip ( `${ argument } unread messages` ) ;
232+ displayTrayIcon ( tray ) ;
211233 }
212234 }
213235 } ) ;
@@ -225,10 +247,8 @@ export function initializeTray(serverManagerView: ServerManagerView) {
225247 } else {
226248 state = true ;
227249 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 ! ) ;
232252 }
233253
234254 ConfigUtil . setConfigItem ( "trayIcon" , true ) ;
@@ -239,6 +259,12 @@ export function initializeTray(serverManagerView: ServerManagerView) {
239259
240260 ipcRenderer . on ( "toggletray" , toggleTray ) ;
241261
262+ ipcRenderer . on ( "toggle-tray-badge-count" , ( ) => {
263+ if ( tray && shouldShowTrayIcon ( ) ) {
264+ displayTrayIcon ( tray ) ;
265+ }
266+ } ) ;
267+
242268 if ( ConfigUtil . getConfigItem ( "trayIcon" , true ) ) {
243269 createTray ( ) ;
244270 }
0 commit comments