@@ -25,29 +25,46 @@ router.post("/hide", (req, res) => {
25
25
} ) ;
26
26
router . post ( "/create" , ( req , res ) => {
27
27
res . sendStatus ( 200 ) ;
28
- const { width, height, url, label, alwaysOnTop, vibrancy, backgroundColor, transparency, icon, showDockIcon, contextMenu } = req . body ;
29
- state_1 . default . activeMenuBar = ( 0 , menubar_1 . menubar ) ( {
30
- icon : icon || state_1 . default . icon . replace ( "icon.png" , "IconTemplate.png" ) ,
31
- index : url ,
32
- showDockIcon,
33
- showOnAllWorkspaces : false ,
34
- browserWindow : {
35
- width,
36
- height,
37
- alwaysOnTop,
38
- vibrancy,
39
- backgroundColor,
40
- transparent : transparency ,
41
- webPreferences : {
42
- nodeIntegration : true ,
43
- sandbox : false ,
44
- contextIsolation : false
28
+ const { width, height, url, label, alwaysOnTop, vibrancy, backgroundColor, transparency, icon, showDockIcon, onlyShowContextWindow, contextMenu } = req . body ;
29
+ if ( onlyShowContextWindow === true ) {
30
+ const tray = new electron_1 . Tray ( icon || state_1 . default . icon . replace ( "icon.png" , "IconTemplate.png" ) ) ;
31
+ tray . setContextMenu ( buildMenu ( contextMenu ) ) ;
32
+ state_1 . default . activeMenuBar = ( 0 , menubar_1 . menubar ) ( {
33
+ tray,
34
+ index : false ,
35
+ showDockIcon,
36
+ showOnAllWorkspaces : false ,
37
+ browserWindow : {
38
+ show : false ,
39
+ width : 0 ,
40
+ height : 0 ,
45
41
}
46
- }
47
- } ) ;
48
- state_1 . default . activeMenuBar . on ( "after-create-window" , ( ) => {
49
- require ( "@electron/remote/main" ) . enable ( state_1 . default . activeMenuBar . window . webContents ) ;
50
- } ) ;
42
+ } ) ;
43
+ }
44
+ else {
45
+ state_1 . default . activeMenuBar = ( 0 , menubar_1 . menubar ) ( {
46
+ icon : icon || state_1 . default . icon . replace ( "icon.png" , "IconTemplate.png" ) ,
47
+ index : url ,
48
+ showDockIcon,
49
+ showOnAllWorkspaces : false ,
50
+ browserWindow : {
51
+ width,
52
+ height,
53
+ alwaysOnTop,
54
+ vibrancy,
55
+ backgroundColor,
56
+ transparent : transparency ,
57
+ webPreferences : {
58
+ nodeIntegration : true ,
59
+ sandbox : false ,
60
+ contextIsolation : false
61
+ }
62
+ }
63
+ } ) ;
64
+ state_1 . default . activeMenuBar . on ( "after-create-window" , ( ) => {
65
+ require ( "@electron/remote/main" ) . enable ( state_1 . default . activeMenuBar . window . webContents ) ;
66
+ } ) ;
67
+ }
51
68
state_1 . default . activeMenuBar . on ( "ready" , ( ) => {
52
69
state_1 . default . activeMenuBar . tray . setTitle ( label ) ;
53
70
state_1 . default . activeMenuBar . on ( "hide" , ( ) => {
@@ -60,17 +77,22 @@ router.post("/create", (req, res) => {
60
77
event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarShown"
61
78
} ) ;
62
79
} ) ;
63
- state_1 . default . activeMenuBar . tray . on ( "right-click" , ( ) => {
64
- ( 0 , utils_1 . notifyLaravel ) ( "events" , {
65
- event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarContextMenuOpened"
80
+ if ( onlyShowContextWindow !== true ) {
81
+ state_1 . default . activeMenuBar . tray . on ( "right-click" , ( ) => {
82
+ ( 0 , utils_1 . notifyLaravel ) ( "events" , {
83
+ event : "\\Native\\Laravel\\Events\\MenuBar\\MenuBarContextMenuOpened"
84
+ } ) ;
85
+ state_1 . default . activeMenuBar . tray . popUpContextMenu ( buildMenu ( contextMenu ) ) ;
66
86
} ) ;
67
- let menu = electron_1 . Menu . buildFromTemplate ( [ { role : "quit" } ] ) ;
68
- if ( contextMenu ) {
69
- const menuEntries = contextMenu . map ( helper_1 . mapMenu ) ;
70
- menu = electron_1 . Menu . buildFromTemplate ( menuEntries ) ;
71
- }
72
- state_1 . default . activeMenuBar . tray . popUpContextMenu ( menu ) ;
73
- } ) ;
87
+ }
74
88
} ) ;
75
89
} ) ;
90
+ function buildMenu ( contextMenu ) {
91
+ let menu = electron_1 . Menu . buildFromTemplate ( [ { role : "quit" } ] ) ;
92
+ if ( contextMenu ) {
93
+ const menuEntries = contextMenu . map ( helper_1 . mapMenu ) ;
94
+ menu = electron_1 . Menu . buildFromTemplate ( menuEntries ) ;
95
+ }
96
+ return menu ;
97
+ }
76
98
exports . default = router ;
0 commit comments