Skip to content

Commit 6d0fbde

Browse files
set contectmenu on correct lifetime..
1 parent b113532 commit 6d0fbde

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ElectronNET.WebApp/Controllers/MenusController.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
using Microsoft.AspNetCore.Mvc;
33
using ElectronNET.API.Entities;
44
using ElectronNET.API;
5+
using Microsoft.Extensions.Hosting;
56

67
namespace 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
}

0 commit comments

Comments
 (0)