File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
ElectronNET.WebApp/Controllers Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 2
2
using Microsoft . AspNetCore . Mvc ;
3
3
using ElectronNET . API . Entities ;
4
4
using ElectronNET . API ;
5
+ using Microsoft . Extensions . Hosting ;
5
6
6
7
namespace ElectronNET . WebApp . Controllers
7
8
{
8
9
public class MenusController : Controller
9
10
{
11
+ public MenusController ( IHostApplicationLifetime hostApplicationLifetime )
12
+ {
13
+ hostApplicationLifetime . ApplicationStarted . Register ( ( ) =>
14
+ {
15
+ if ( HybridSupport . IsElectronActive )
16
+ {
17
+ CreateContextMenu ( ) ;
18
+ }
19
+ } ) ;
20
+ }
21
+
10
22
public IActionResult Index ( )
11
23
{
12
24
if ( HybridSupport . IsElectronActive )
@@ -93,7 +105,6 @@ public IActionResult Index()
93
105
94
106
Electron . Menu . SetApplicationMenu ( menu ) ;
95
107
96
- CreateContextMenu ( ) ;
97
108
}
98
109
99
110
return View ( ) ;
@@ -113,12 +124,11 @@ private void CreateContextMenu()
113
124
} ;
114
125
115
126
var mainWindow = Electron . WindowManager . BrowserWindows . FirstOrDefault ( ) ;
116
- if ( mainWindow == null ) return ;
117
-
118
127
Electron . Menu . SetContextMenu ( mainWindow , menu ) ;
119
128
120
129
Electron . IpcMain . On ( "show-context-menu" , ( args ) =>
121
130
{
131
+ var mainWindow = Electron . WindowManager . BrowserWindows . FirstOrDefault ( ) ;
122
132
Electron . Menu . ContextMenuPopup ( mainWindow ) ;
123
133
} ) ;
124
134
}
You can’t perform that action at this time.
0 commit comments