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 22using Microsoft . AspNetCore . Mvc ;
33using ElectronNET . API . Entities ;
44using ElectronNET . API ;
5+ using Microsoft . Extensions . Hosting ;
56
67namespace ElectronNET . WebApp . Controllers
78{
89 public class MenusController : Controller
910 {
11+ public MenusController ( IHostApplicationLifetime hostApplicationLifetime )
12+ {
13+ hostApplicationLifetime . ApplicationStarted . Register ( ( ) =>
14+ {
15+ if ( HybridSupport . IsElectronActive )
16+ {
17+ CreateContextMenu ( ) ;
18+ }
19+ } ) ;
20+ }
21+
1022 public IActionResult Index ( )
1123 {
1224 if ( HybridSupport . IsElectronActive )
@@ -93,7 +105,6 @@ public IActionResult Index()
93105
94106 Electron . Menu . SetApplicationMenu ( menu ) ;
95107
96- CreateContextMenu ( ) ;
97108 }
98109
99110 return View ( ) ;
@@ -113,12 +124,11 @@ private void CreateContextMenu()
113124 } ;
114125
115126 var mainWindow = Electron . WindowManager . BrowserWindows . FirstOrDefault ( ) ;
116- if ( mainWindow == null ) return ;
117-
118127 Electron . Menu . SetContextMenu ( mainWindow , menu ) ;
119128
120129 Electron . IpcMain . On ( "show-context-menu" , ( args ) =>
121130 {
131+ var mainWindow = Electron . WindowManager . BrowserWindows . FirstOrDefault ( ) ;
122132 Electron . Menu . ContextMenuPopup ( mainWindow ) ;
123133 } ) ;
124134 }
You can’t perform that action at this time.
0 commit comments