@@ -12,34 +12,63 @@ class AppTray
12
12
constructor ( windowManager ) {
13
13
this . windowManager = windowManager
14
14
this . tray = new Tray ( this . _resolveIcon ( ) )
15
+ this . tray . setContextMenu ( this . _createContextMenu ( ) )
16
+ this . tray . closeContextMenu ( )
15
17
}
16
18
17
19
setHandlers ( )
18
20
{
19
21
this . tray . on ( 'double-click' , this . _toggleWindow . bind ( this ) )
20
22
this . tray . on ( 'click' , event => {
21
- this . tray . setContextMenu ( null )
22
-
23
- const mainWindow = this . windowManager . getMainWindow ( )
24
-
25
- this . _toggleWindow ( )
26
-
27
- if ( mainWindow . isVisible ( ) && process . defaultApp && event . metaKey ) {
28
- mainWindow . openDevTools ( { mode : 'detach' } )
23
+ if ( process . platform === 'darwin' ) {
24
+ this . tray . setContextMenu ( null )
29
25
}
26
+
27
+ this . _showMainWindow ( event )
30
28
} )
29
+
31
30
this . tray . on ( 'right-click' , ( ) => {
32
- const contextMenu = Menu . buildFromTemplate ( [
33
- {
34
- label : 'Help' , click : ( ) => {
35
- new OpenInShellHandler ( ) . handle ( { payload : 'https://github.com/Doka-NT/worklog-reminder' } )
36
- }
37
- } ,
38
- { label : 'Quit' , click : ( ) => app . quit ( ) } ,
39
- ] )
40
-
41
- this . tray . setContextMenu ( contextMenu )
31
+ if ( process . platform === 'darwin' ) {
32
+ this . tray . setContextMenu ( this . _createContextMenu ( ) )
33
+ }
34
+ this . tray . popUpContextMenu ( )
42
35
} )
36
+
37
+ }
38
+
39
+ _showMainWindow ( event )
40
+ {
41
+ const mainWindow = this . windowManager . getMainWindow ( )
42
+
43
+ this . _toggleWindow ( )
44
+
45
+ if ( mainWindow . isVisible ( ) && process . defaultApp && event . metaKey ) {
46
+ mainWindow . openDevTools ( { mode : 'detach' } )
47
+ }
48
+ }
49
+
50
+ _createContextMenu ( )
51
+ {
52
+ const menuItems = [
53
+ {
54
+ label : 'Help' ,
55
+ click : ( ) => {
56
+ new OpenInShellHandler ( ) . handle ( { payload : 'https://github.com/Doka-NT/worklog-reminder' } )
57
+ }
58
+ } ,
59
+ { label : 'Quit' , click : ( ) => app . quit ( ) } ,
60
+ ]
61
+
62
+ if ( process . platform === 'linux' ) {
63
+ menuItems . unshift ( {
64
+ label : 'Toggle Window' ,
65
+ click : ( event ) => {
66
+ this . _showMainWindow ( event )
67
+ }
68
+ } )
69
+ }
70
+
71
+ return Menu . buildFromTemplate ( menuItems )
43
72
}
44
73
45
74
_resolveIcon ( )
0 commit comments