@@ -19,12 +19,18 @@ const icons = {
19
19
20
20
darwin : {
21
21
dir : 'osx' ,
22
- icon : 'icon-trayTemplate.png'
22
+ icon : 'icon-trayTemplate.png' ,
23
+ iconAlert : 'icon-tray-alert.png' ,
24
+ title : {
25
+ online : '\u001B[32m' ,
26
+ away : '\u001B[33m' ,
27
+ busy : '\u001B[31m' ,
28
+ offline : '\u001B[30m'
29
+ }
23
30
}
24
31
} ;
25
32
26
33
const _iconTray = path . join ( __dirname , 'images' , icons [ process . platform ] . dir , icons [ process . platform ] . icon || 'icon-tray.png' ) ;
27
- const _iconTrayAlert = path . join ( __dirname , 'images' , icons [ process . platform ] . dir , icons [ process . platform ] . iconAlert || 'icon-tray-alert.png' ) ;
28
34
29
35
function createAppTray ( ) {
30
36
const _tray = new Tray ( _iconTray ) ;
@@ -95,34 +101,38 @@ function createAppTray () {
95
101
} ;
96
102
}
97
103
98
- function setImage ( title ) {
104
+ function getImageTitle ( title ) {
99
105
if ( title === '•' ) {
100
- title = "Dot" ;
106
+ return "Dot" ;
101
107
} else if ( ! isNaN ( parseInt ( title ) ) && title > 9 ) {
102
- title = "9Plus" ;
108
+ return "9Plus" ;
103
109
}
110
+ }
104
111
105
- const _iconPath = path . join ( __dirname , 'images' , icons [ process . platform ] . dir , `icon-tray${ title } .png` ) ;
106
- mainWindow . tray . setImage ( _iconPath ) ;
112
+ function getTrayIcon ( platform , showAlert , title , status ) {
113
+ if ( platform !== 'darwin' ) {
114
+ return path . join ( __dirname , 'images' , icons [ process . platform ] . dir , `icon-tray${ title } -${ status } .png` ) ;
115
+ }
116
+
117
+ if ( showAlert ) {
118
+ return path . join ( __dirname , 'images' , icons [ process . platform ] . dir , icons [ process . platform ] . iconAlert || `icon-tray-alert-${ status } Template.png` ) ;
119
+ } else {
120
+ return path . join ( __dirname , 'images' , icons [ process . platform ] . dir , icons [ process . platform ] . icon || `icon-tray-${ status } Template.png` ) ;
121
+ }
107
122
}
108
123
109
- function showTrayAlert ( showAlert , title ) {
124
+ function showTrayAlert ( showAlert , title , status = 'online' ) {
110
125
if ( mainWindow . tray === null || mainWindow . tray === undefined ) {
111
126
return ;
112
127
}
113
128
114
- mainWindow . flashFrame ( showAlert ) ;
115
- if ( process . platform !== 'darwin' ) {
116
- setImage ( title ) ;
117
- } else {
118
- if ( showAlert ) {
119
- mainWindow . tray . setImage ( _iconTrayAlert ) ;
120
- } else {
121
- mainWindow . tray . setImage ( _iconTray ) ;
122
- }
123
- mainWindow . tray . setTitle ( title ) ;
124
- }
129
+ mainWindow . flashFrame ( showAlert , title ) ;
130
+ const trayImagePath = getTrayIcon ( process . platform , showAlert , getImageTitle ( title ) , status ) ;
131
+ mainWindow . tray . setImage ( trayImagePath ) ;
125
132
133
+ if ( process . platform === 'darwin' ) {
134
+ mainWindow . tray . setTitle ( `${ icons [ process . platform ] . title [ status ] } ${ title } ` ) ;
135
+ }
126
136
}
127
137
128
138
function removeAppTray ( ) {
0 commit comments