@@ -77,6 +77,13 @@ function alarmSet() {
77
77
}
78
78
}
79
79
80
+ function setFullScreenMode ( flag ) {
81
+ if ( win != null ) {
82
+ if ( process . platform == "darwin" ) win . setSimpleFullScreen ( flag ) ;
83
+ else win . setFullScreen ( flag )
84
+ }
85
+ }
86
+
80
87
//before quit
81
88
app . on ( 'will-quit' , ( ) => {
82
89
globalShortcut . unregisterAll ( )
@@ -153,59 +160,9 @@ app.on('ready', () => {
153
160
}
154
161
155
162
if ( process . platform == "win32" ) tray = new Tray ( path . join ( __dirname , '\\res\\icons\\iconWin.ico' ) ) ;
156
- else if ( process . platform != "darwin" ) tray = new Tray ( path . join ( __dirname , '\\res\\icons\\wnrIcon.png' ) ) ;
157
- contextMenu = Menu . buildFromTemplate ( [
158
- {
159
- label : 'wnr' + i18n . __ ( 'v' ) + require ( "./package.json" ) . version
160
- } , {
161
- type : 'separator'
162
- } , {
163
- label : i18n . __ ( 'start-or-stop' ) ,
164
- enabled : false ,
165
- click : function ( ) {
166
- if ( win != null ) win . webContents . send ( 'start-or-stop' )
167
- }
168
- } , {
169
- type : 'separator'
170
- } , {
171
- label : i18n . __ ( 'website' ) ,
172
- click : function ( ) {
173
- shell . openExternal ( 'https://wnr.scris.top/' ) ;
174
- }
175
- } , {
176
- label : i18n . __ ( 'help-page' ) ,
177
- click : function ( ) {
178
- shell . openExternal ( 'https://wnr.scris.top/help.html' ) ;
179
- }
180
- } , {
181
- label : i18n . __ ( 'github' ) ,
182
- click : function ( ) {
183
- shell . openExternal ( 'https://github.com/RoderickQiu/wnr/' ) ;
184
- }
185
- } , {
186
- type : 'separator'
187
- } , {
188
- label : i18n . __ ( 'show-or-hide' ) , click : ( ) => {
189
- if ( win != null ) win . isVisible ( ) ? win . hide ( ) : win . show ( ) ;
190
- if ( settingsWin != null ) settingsWin . isVisible ( ) ? settingsWin . hide ( ) : settingsWin . show ( ) ;
191
- if ( aboutWin != null ) aboutWin . isVisible ( ) ? aboutWin . hide ( ) : aboutWin . show ( ) ;
192
- if ( tourWin != null ) tourWin . isVisible ( ) ? tourWin . hide ( ) : tourWin . show ( ) ;
193
- }
194
- } , {
195
- label : i18n . __ ( 'exit' ) , click : ( ) => { windowCloseChk ( ) }
196
- }
197
- ] ) ;
198
- if ( tray != null ) {
199
- tray . setToolTip ( 'wnr' ) ;
200
- tray . setContextMenu ( contextMenu ) ;
201
- tray . on ( 'click' , ( ) => {
202
- if ( win != null ) win . isVisible ( ) ? win . hide ( ) : win . show ( ) ;
203
- if ( settingsWin != null ) settingsWin . isVisible ( ) ? settingsWin . hide ( ) : settingsWin . show ( ) ;
204
- if ( aboutWin != null ) aboutWin . isVisible ( ) ? aboutWin . hide ( ) : aboutWin . show ( ) ;
205
- if ( tourWin != null ) tourWin . isVisible ( ) ? tourWin . hide ( ) : tourWin . show ( ) ;
206
- } ) ; //tray
207
- }
208
-
163
+ else if ( process . platform == "darwin" ) tray = new Tray ( path . join ( __dirname , '/res/icons/trayIconMacTemplate.png' ) ) ;
164
+ if ( tray != null ) tray . setToolTip ( 'wnr' ) ;
165
+ traySolution ( false ) ;
209
166
macOSFullscreenSolution ( false ) ;
210
167
isDarkMode ( ) ;
211
168
@@ -253,6 +210,82 @@ app.on('ready', () => {
253
210
} //alternated the former default time settings
254
211
} )
255
212
213
+ function traySolution ( isFullScreen ) {
214
+ if ( app . isReady ( ) ) {
215
+ if ( ! isFullScreen ) {
216
+ if ( process . platform == "darwin" ) app . dock . show ( ) ;
217
+ contextMenu = Menu . buildFromTemplate ( [
218
+ {
219
+ label : 'wnr' + i18n . __ ( 'v' ) + require ( "./package.json" ) . version
220
+ } , {
221
+ type : 'separator'
222
+ } , {
223
+ label : i18n . __ ( 'start-or-stop' ) ,
224
+ enabled : false ,
225
+ click : function ( ) {
226
+ if ( win != null ) win . webContents . send ( 'start-or-stop' )
227
+ }
228
+ } , {
229
+ type : 'separator'
230
+ } ,
231
+ {
232
+ label : i18n . __ ( 'website' ) ,
233
+ click : function ( ) {
234
+ shell . openExternal ( 'https://wnr.scris.top/' ) ;
235
+ }
236
+ } , {
237
+ label : i18n . __ ( 'help-page' ) ,
238
+ click : function ( ) {
239
+ shell . openExternal ( 'https://wnr.scris.top/help.html' ) ;
240
+ }
241
+ } , {
242
+ label : i18n . __ ( 'github' ) ,
243
+ click : function ( ) {
244
+ shell . openExternal ( 'https://github.com/RoderickQiu/wnr/' ) ;
245
+ }
246
+ } , {
247
+ type : 'separator'
248
+ } , {
249
+ label : i18n . __ ( 'show-or-hide' ) , click : ( ) => {
250
+ if ( win != null ) win . isVisible ( ) ? win . hide ( ) : win . show ( ) ;
251
+ if ( settingsWin != null ) settingsWin . isVisible ( ) ? settingsWin . hide ( ) : settingsWin . show ( ) ;
252
+ if ( aboutWin != null ) aboutWin . isVisible ( ) ? aboutWin . hide ( ) : aboutWin . show ( ) ;
253
+ if ( tourWin != null ) tourWin . isVisible ( ) ? tourWin . hide ( ) : tourWin . show ( ) ;
254
+ }
255
+ } , {
256
+ label : i18n . __ ( 'exit' ) , click : ( ) => { windowCloseChk ( ) }
257
+ }
258
+ ] ) ;
259
+ if ( tray != null ) {
260
+ tray . on ( 'click' , ( ) => {
261
+ if ( win != null ) win . isVisible ( ) ? win . hide ( ) : win . show ( ) ;
262
+ if ( settingsWin != null ) settingsWin . isVisible ( ) ? settingsWin . hide ( ) : settingsWin . show ( ) ;
263
+ if ( aboutWin != null ) aboutWin . isVisible ( ) ? aboutWin . hide ( ) : aboutWin . show ( ) ;
264
+ if ( tourWin != null ) tourWin . isVisible ( ) ? tourWin . hide ( ) : tourWin . show ( ) ;
265
+ } ) ; //tray
266
+ tray . setContextMenu ( contextMenu ) ;
267
+ }
268
+ } else {
269
+ if ( process . platform == "darwin" ) app . dock . hide ( ) ;
270
+ contextMenu = Menu . buildFromTemplate ( [
271
+ {
272
+ label : 'wnr' + i18n . __ ( 'v' ) + require ( "./package.json" ) . version
273
+ } , {
274
+ type : 'separator'
275
+ } , {
276
+ label : i18n . __ ( 'start-or-stop' ) ,
277
+ click : function ( ) {
278
+ if ( win != null ) win . webContents . send ( 'start-or-stop' )
279
+ }
280
+ } ] ) ;
281
+ if ( tray != null ) {
282
+ tray . setContextMenu ( contextMenu ) ;
283
+ tray . on ( 'click' , ( ) => { ; } )
284
+ }
285
+ }
286
+ }
287
+ }
288
+
256
289
function macOSFullscreenSolution ( isFullScreen ) {
257
290
if ( app . isReady ( ) ) {
258
291
if ( process . platform === 'darwin' ) {
@@ -334,8 +367,7 @@ function macOSFullscreenSolution(isFullScreen) {
334
367
} ]
335
368
} ] ;
336
369
var osxMenu = Menu . buildFromTemplate ( template ) ;
337
- Menu . setApplicationMenu ( osxMenu ) ;
338
- app . dock . setMenu ( osxMenu )
370
+ Menu . setApplicationMenu ( osxMenu )
339
371
} //dock menu for mac os
340
372
}
341
373
}
@@ -386,8 +418,9 @@ app.on('activate', () => {
386
418
387
419
ipcMain . on ( 'focus-first' , function ( ) {
388
420
if ( store . get ( "top" ) != true && win != null ) win . setAlwaysOnTop ( true ) ; //always on top when full screen
389
- if ( win != null ) win . setFullScreen ( true ) ;
421
+ if ( win != null ) setFullScreenMode ( true ) ;
390
422
macOSFullscreenSolution ( true ) ;
423
+ traySolution ( true ) ;
391
424
isWorkMode = true ;
392
425
store . set ( "fullscreen-protection" , true ) ;
393
426
} )
@@ -402,12 +435,14 @@ ipcMain.on('warning-giver-workend', function () {
402
435
win . flashFrame ( true ) ;
403
436
if ( store . get ( "fullscreen" ) == true ) {
404
437
if ( store . get ( "top" ) != true ) win . setAlwaysOnTop ( true ) ; //always on top when full screen
405
- win . setFullScreen ( true ) ;
438
+ setFullScreenMode ( true ) ;
406
439
macOSFullscreenSolution ( true ) ;
440
+ traySolution ( true ) ;
407
441
} else {
408
442
if ( store . get ( "top" ) != true ) win . setAlwaysOnTop ( false ) ; //cancel unnecessary always-on-top
409
- win . setFullScreen ( false ) ;
443
+ setFullScreenMode ( false ) ;
410
444
macOSFullscreenSolution ( false ) ;
445
+ traySolution ( false ) ;
411
446
}
412
447
setTimeout ( function ( ) {
413
448
dialog . showMessageBox ( win , {
@@ -430,12 +465,14 @@ ipcMain.on('warning-giver-restend', function () {
430
465
win . flashFrame ( true ) ;
431
466
if ( store . get ( "fullscreen-work" ) == true ) {
432
467
if ( store . get ( "top" ) != true ) win . setAlwaysOnTop ( true ) ; //always on top when full screen
433
- win . setFullScreen ( true ) ;
468
+ setFullScreenMode ( true ) ;
434
469
macOSFullscreenSolution ( true ) ;
470
+ traySolution ( true ) ;
435
471
} else {
436
472
if ( store . get ( "top" ) != true ) win . setAlwaysOnTop ( false ) ; //cancel unnecessary always-on-top
437
- win . setFullScreen ( false ) ;
473
+ setFullScreenMode ( false ) ;
438
474
macOSFullscreenSolution ( false ) ;
475
+ traySolution ( false ) ;
439
476
}
440
477
setTimeout ( function ( ) {
441
478
dialog . showMessageBox ( win , {
@@ -458,8 +495,9 @@ ipcMain.on('warning-giver-all-task-end', function () {
458
495
win . flashFrame ( true ) ;
459
496
if ( store . get ( "fullscreen" ) == true ) {
460
497
if ( store . get ( "top" ) != true ) win . setAlwaysOnTop ( false ) ; //cancel unnecessary always-on-top
461
- win . setFullScreen ( false ) ;
498
+ setFullScreenMode ( false ) ;
462
499
macOSFullscreenSolution ( false ) ;
500
+ traySolution ( false ) ;
463
501
}
464
502
setTimeout ( function ( ) {
465
503
dialog . showMessageBox ( win , {
0 commit comments