@@ -9,138 +9,173 @@ import { join } from "path";
9
9
const router = express . Router ( ) ;
10
10
11
11
router . post ( "/label" , ( req , res ) => {
12
- res . sendStatus ( 200 ) ;
12
+ res . sendStatus ( 200 ) ;
13
13
14
- const { label } = req . body ;
14
+ const { label } = req . body ;
15
15
16
- state . activeMenuBar . tray . setTitle ( label ) ;
16
+ state . activeMenuBar . tray . setTitle ( label ) ;
17
+ } ) ;
18
+
19
+ router . post ( "/tooltip" , ( req , res ) => {
20
+ res . sendStatus ( 200 ) ;
21
+
22
+ const { tooltip } = req . body ;
23
+
24
+ state . activeMenuBar . tray . setToolTip ( tooltip ) ;
25
+ } ) ;
26
+
27
+ router . post ( "/icon" , ( req , res ) => {
28
+ res . sendStatus ( 200 ) ;
29
+
30
+ const { icon } = req . body ;
31
+
32
+ state . activeMenuBar . tray . setImage ( icon ) ;
17
33
} ) ;
18
34
19
35
router . post ( "/context-menu" , ( req , res ) => {
20
- res . sendStatus ( 200 ) ;
21
- const { contextMenu } = req . body ;
22
-
23
- state . activeMenuBar . tray . setContextMenu ( buildMenu ( contextMenu ) ) ;
36
+ res . sendStatus ( 200 ) ;
37
+
38
+ const { contextMenu } = req . body ;
39
+
40
+ state . activeMenuBar . tray . setContextMenu ( buildMenu ( contextMenu ) ) ;
24
41
} ) ;
25
42
26
43
router . post ( "/show" , ( req , res ) => {
27
- res . sendStatus ( 200 ) ;
44
+ res . sendStatus ( 200 ) ;
28
45
29
- state . activeMenuBar . showWindow ( ) ;
46
+ state . activeMenuBar . showWindow ( ) ;
30
47
} ) ;
31
48
32
49
router . post ( "/hide" , ( req , res ) => {
33
- res . sendStatus ( 200 ) ;
50
+ res . sendStatus ( 200 ) ;
34
51
35
- state . activeMenuBar . hideWindow ( ) ;
52
+ state . activeMenuBar . hideWindow ( ) ;
36
53
} ) ;
37
54
38
55
router . post ( "/create" , ( req , res ) => {
39
- res . sendStatus ( 200 ) ;
40
-
41
- const {
42
- width,
43
- height,
44
- url,
45
- label,
46
- alwaysOnTop,
47
- vibrancy,
48
- backgroundColor,
49
- transparency,
50
- icon,
51
- showDockIcon,
52
- onlyShowContextWindow,
53
- windowPosition,
54
- contextMenu
55
- } = req . body ;
56
-
57
- if ( onlyShowContextWindow === true ) {
58
- const tray = new Tray ( icon || state . icon . replace ( "icon.png" , "IconTemplate.png" ) ) ;
59
- tray . setContextMenu ( buildMenu ( contextMenu ) ) ;
60
-
61
- state . activeMenuBar = menubar ( {
62
- tray,
63
- index : false ,
64
- showDockIcon,
65
- showOnAllWorkspaces : false ,
66
- browserWindow : {
67
- show : false ,
68
- width : 0 ,
69
- height : 0 ,
70
- }
71
- } ) ;
56
+ res . sendStatus ( 200 ) ;
72
57
73
- } else {
74
- state . activeMenuBar = menubar ( {
75
- icon : icon || state . icon . replace ( "icon.png" , "IconTemplate.png" ) ,
76
- index : url ,
77
- showDockIcon,
78
- showOnAllWorkspaces : false ,
79
- windowPosition : windowPosition ?? "trayCenter" ,
80
- browserWindow : {
58
+ const {
81
59
width,
82
60
height,
61
+ url,
62
+ label,
83
63
alwaysOnTop,
84
64
vibrancy,
85
65
backgroundColor,
86
- transparent : transparency ,
87
- webPreferences : {
88
- nodeIntegration : true ,
89
- sandbox : false ,
90
- contextIsolation : false
66
+ transparency,
67
+ icon,
68
+ showDockIcon,
69
+ onlyShowContextMenu,
70
+ windowPosition,
71
+ contextMenu,
72
+ tooltip,
73
+ resizable,
74
+ event,
75
+ } = req . body ;
76
+
77
+ if ( onlyShowContextMenu ) {
78
+ const tray = new Tray ( icon || state . icon . replace ( "icon.png" , "IconTemplate.png" ) ) ;
79
+
80
+ tray . setContextMenu ( buildMenu ( contextMenu ) ) ;
81
+
82
+ if ( event ) {
83
+ tray . on ( 'click' , ( e ) => {
84
+ notifyLaravel ( 'events' , {
85
+ event,
86
+ payload : e ,
87
+ } ) ;
88
+ } ) ;
91
89
}
92
- }
93
- } ) ;
94
- state . activeMenuBar . on ( "after-create-window" , ( ) => {
95
- require ( "@electron/remote/main" ) . enable ( state . activeMenuBar . window . webContents ) ;
96
- } ) ;
97
- }
98
90
99
- state . activeMenuBar . on ( "ready" , ( ) => {
100
- state . activeMenuBar . tray . setTitle ( label ) ;
91
+ state . activeMenuBar = menubar ( {
92
+ tray,
93
+ tooltip,
94
+ index : false ,
95
+ showDockIcon,
96
+ showOnAllWorkspaces : false ,
97
+ browserWindow : {
98
+ show : false ,
99
+ width : 0 ,
100
+ height : 0 ,
101
+ }
102
+ } ) ;
103
+ } else {
104
+ state . activeMenuBar = menubar ( {
105
+ icon : icon || state . icon . replace ( "icon.png" , "IconTemplate.png" ) ,
106
+ preloadWindow : true ,
107
+ tooltip,
108
+ index : url ,
109
+ showDockIcon,
110
+ showOnAllWorkspaces : false ,
111
+ windowPosition : windowPosition ?? "trayCenter" ,
112
+ browserWindow : {
113
+ width,
114
+ height,
115
+ resizable,
116
+ alwaysOnTop,
117
+ vibrancy,
118
+ backgroundColor,
119
+ transparent : transparency ,
120
+ webPreferences : {
121
+ preload : join ( __dirname , '../../electron-plugin/dist/preload/index.js' ) ,
122
+ nodeIntegration : true ,
123
+ sandbox : false ,
124
+ contextIsolation : false ,
125
+ }
126
+ }
127
+ } ) ;
101
128
102
- state . activeMenuBar . on ( "hide" , ( ) => {
103
- notifyLaravel ( "events" , {
104
- event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarHidden"
105
- } ) ;
106
- } ) ;
129
+ state . activeMenuBar . on ( "after-create-window" , ( ) => {
130
+ require ( "@electron/remote/main" ) . enable ( state . activeMenuBar . window . webContents ) ;
131
+ } ) ;
132
+ }
107
133
108
- state . activeMenuBar . on ( "show" , ( ) => {
109
- notifyLaravel ( "events" , {
110
- event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarShown"
111
- } ) ;
112
- } ) ;
134
+ state . activeMenuBar . on ( "ready" , ( ) => {
135
+ state . activeMenuBar . tray . setTitle ( label ) ;
113
136
114
- state . activeMenuBar . tray . on ( "drop-files" , ( event , files ) => {
115
- notifyLaravel ( "events" , {
116
- event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarDroppedFiles" ,
117
- payload : [
118
- files
119
- ]
120
- } ) ;
121
- } ) ;
137
+ state . activeMenuBar . on ( "hide" , ( ) => {
138
+ notifyLaravel ( "events" , {
139
+ event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarHidden"
140
+ } ) ;
141
+ } ) ;
122
142
123
- if ( onlyShowContextWindow !== true ) {
124
- state . activeMenuBar . tray . on ( "right-click" , ( ) => {
125
- notifyLaravel ( "events" , {
126
- event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarContextMenuOpened"
143
+ state . activeMenuBar . on ( "show" , ( ) => {
144
+ notifyLaravel ( "events" , {
145
+ event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarShown"
146
+ } ) ;
127
147
} ) ;
128
148
129
- state . activeMenuBar . tray . popUpContextMenu ( buildMenu ( contextMenu ) ) ;
130
- } ) ;
131
- }
132
- } ) ;
149
+ state . activeMenuBar . tray . on ( "drop-files" , ( event , files ) => {
150
+ notifyLaravel ( "events" , {
151
+ event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarDroppedFiles" ,
152
+ payload : [
153
+ files
154
+ ]
155
+ } ) ;
156
+ } ) ;
157
+
158
+ if ( ! onlyShowContextMenu ) {
159
+ state . activeMenuBar . tray . on ( "right-click" , ( ) => {
160
+ notifyLaravel ( "events" , {
161
+ event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarContextMenuOpened"
162
+ } ) ;
163
+
164
+ state . activeMenuBar . tray . popUpContextMenu ( buildMenu ( contextMenu ) ) ;
165
+ } ) ;
166
+ }
167
+ } ) ;
133
168
} ) ;
134
169
135
170
function buildMenu ( contextMenu ) {
136
- let menu = Menu . buildFromTemplate ( [ { role : "quit" } ] ) ;
171
+ let menu = Menu . buildFromTemplate ( [ { role : "quit" } ] ) ;
137
172
138
- if ( contextMenu ) {
139
- const menuEntries = contextMenu . map ( mapMenu ) ;
140
- menu = Menu . buildFromTemplate ( menuEntries ) ;
141
- }
173
+ if ( contextMenu ) {
174
+ const menuEntries = contextMenu . map ( mapMenu ) ;
175
+ menu = Menu . buildFromTemplate ( menuEntries ) ;
176
+ }
142
177
143
- return menu ;
178
+ return menu ;
144
179
}
145
180
146
181
export default router ;
0 commit comments