Skip to content

Commit 046a171

Browse files
Migrate to .NET 6 and Electron.NET 23.6.1
1 parent 3e27644 commit 046a171

40 files changed

+6971
-188
lines changed

AnalysisReport.sarif

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
3+
"version": "2.1.0",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "Dependency Analysis",
9+
"semanticVersion": "0.4.355802",
10+
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview",
11+
"rules": [
12+
{
13+
"id": "UA106",
14+
"name": "PackageToBeAdded",
15+
"fullDescription": {
16+
"text": "Packages that need to be added in order to upgrade the project to chosen TFM"
17+
},
18+
"helpUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
19+
}
20+
]
21+
}
22+
},
23+
"results": [
24+
{
25+
"ruleId": "UA106",
26+
"message": {
27+
"text": "Package Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.4.410601 needs to be added."
28+
},
29+
"locations": [
30+
{
31+
"physicalLocation": {
32+
"artifactLocation": {
33+
"uri": "file:///C:/Users/Gregor/source/repos/electron.net-api-demos/ElectronNET-API-Demos/ElectronNET-API-Demos.csproj"
34+
},
35+
"region": {}
36+
}
37+
}
38+
]
39+
},
40+
{
41+
"ruleId": "UA106",
42+
"message": {
43+
"text": "Package Microsoft.AspNetCore.Mvc.NewtonsoftJson, Version=7.0.4 needs to be added."
44+
},
45+
"locations": [
46+
{
47+
"physicalLocation": {
48+
"artifactLocation": {
49+
"uri": "file:///C:/Users/Gregor/source/repos/electron.net-api-demos/ElectronNET-API-Demos/ElectronNET-API-Demos.csproj"
50+
},
51+
"region": {}
52+
}
53+
}
54+
]
55+
}
56+
],
57+
"columnKind": "utf16CodeUnits"
58+
},
59+
{
60+
"tool": {
61+
"driver": {
62+
"name": "API Upgradability",
63+
"semanticVersion": "0.4.355802",
64+
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
65+
}
66+
},
67+
"results": [],
68+
"columnKind": "utf16CodeUnits"
69+
},
70+
{
71+
"tool": {
72+
"driver": {
73+
"name": "Component Analysis",
74+
"semanticVersion": "0.4.355802",
75+
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
76+
}
77+
},
78+
"results": [],
79+
"columnKind": "utf16CodeUnits"
80+
}
81+
]
82+
}

ElectronNET-API-Demos/Controllers/AboutController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22

3-
namespace ElectronNET_API_Demos.Controllers
3+
namespace ElectronNET.WebApp.Controllers
44
{
55
public class AboutController : Controller
66
{

ElectronNET-API-Demos/Controllers/AppSysInformationController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using ElectronNET.API;
44
using ElectronNET.API.Entities;
55

6-
namespace ElectronNET_API_Demos.Controllers
6+
namespace ElectronNET.WebApp.Controllers
77
{
88
public class AppSysInformationController : Controller
99
{
@@ -21,7 +21,7 @@ public IActionResult Index()
2121

2222
Electron.IpcMain.On("sys-info", async (args) =>
2323
{
24-
string homePath = await Electron.App.GetPathAsync(PathName.home);
24+
string homePath = await Electron.App.GetPathAsync(PathName.Home);
2525

2626
var mainWindow = Electron.WindowManager.BrowserWindows.First();
2727
Electron.IpcMain.Send(mainWindow, "got-sys-info", homePath);

ElectronNET-API-Demos/Controllers/ClipboardController.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System;
2+
using System.Drawing;
3+
using System.IO;
4+
using Microsoft.AspNetCore.Mvc;
25
using ElectronNET.API;
36
using System.Linq;
7+
using ElectronNET.API.Entities;
8+
using Newtonsoft.Json;
49

5-
namespace ElectronNET_API_Demos.Controllers
10+
namespace ElectronNET.WebApp.Controllers
611
{
712
public class ClipboardController : Controller
813
{
@@ -23,6 +28,19 @@ public IActionResult Index()
2328
var mainWindow = Electron.WindowManager.BrowserWindows.First();
2429
Electron.IpcMain.Send(mainWindow, "paste-from", pasteText);
2530
});
31+
32+
Electron.IpcMain.On("copy-image-to", (test) =>
33+
{
34+
var nativeImage = NativeImage.CreateFromDataURL(test.ToString());
35+
Electron.Clipboard.WriteImage(nativeImage);
36+
});
37+
38+
Electron.IpcMain.On("paste-image-to", async test =>
39+
{
40+
var nativeImage = await Electron.Clipboard.ReadImageAsync();
41+
var mainWindow = Electron.WindowManager.BrowserWindows.First();
42+
Electron.IpcMain.Send(mainWindow, "paste-image-from", JsonConvert.SerializeObject(nativeImage));
43+
});
2644
}
2745

2846
return View();

ElectronNET-API-Demos/Controllers/CrashHangController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using ElectronNET.API;
33
using ElectronNET.API.Entities;
44

5-
namespace ElectronNET_API_Demos.Controllers
5+
namespace ElectronNET.WebApp.Controllers
66
{
77
public class CrashHangController : Controller
88
{

ElectronNET-API-Demos/Controllers/DesktopCapturerController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22

3-
namespace ElectronNET_API_Demos.Controllers
3+
namespace ElectronNET.WebApp.Controllers
44
{
55
public class DesktopCapturerController : Controller
66
{

ElectronNET-API-Demos/Controllers/DialogsController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using ElectronNET.API;
44
using ElectronNET.API.Entities;
55

6-
namespace ElectronNET_API_Demos.Controllers
6+
namespace ElectronNET.WebApp.Controllers
77
{
88
public class DialogsController : Controller
99
{

ElectronNET-API-Demos/Controllers/HomeController.cs

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
11
using Microsoft.AspNetCore.Mvc;
2+
using ElectronNET.API;
3+
using System;
24

3-
namespace ElectronNET_API_Demos.Controllers
5+
namespace ElectronNET.WebApp.Controllers
46
{
57
public class HomeController : Controller
68
{
79
public IActionResult Index()
810
{
11+
if (HybridSupport.IsElectronActive)
12+
{
13+
Electron.PowerMonitor.OnLockScreen += () =>
14+
{
15+
Console.WriteLine("Screen Locked detected from C#");
16+
};
17+
18+
Electron.PowerMonitor.OnUnLockScreen += () =>
19+
{
20+
Console.WriteLine("Screen unlocked detected from C# ");
21+
};
22+
23+
Electron.PowerMonitor.OnSuspend += () =>
24+
{
25+
Console.WriteLine("The system is going to sleep");
26+
};
27+
28+
Electron.PowerMonitor.OnResume += () =>
29+
{
30+
Console.WriteLine("The system is resuming");
31+
};
32+
33+
Electron.PowerMonitor.OnAC += () =>
34+
{
35+
Console.WriteLine("The system changes to AC power");
36+
};
37+
38+
Electron.PowerMonitor.OnBattery += () =>
39+
{
40+
Console.WriteLine("The system is about to change to battery power");
41+
};
42+
43+
}
44+
945
return View();
1046
}
1147
}

ElectronNET-API-Demos/Controllers/HostHookController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.AspNetCore.Mvc;
44
using System.Linq;
55

6-
namespace ElectronNET_API_Demos.Controllers
6+
namespace ElectronNET.WebApp.Controllers
77
{
88
public class HostHookController : Controller
99
{

ElectronNET-API-Demos/Controllers/IpcController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using ElectronNET.API;
33
using System.Linq;
44

5-
namespace ElectronNET_API_Demos.Controllers
5+
namespace ElectronNET.WebApp.Controllers
66
{
77
public class IpcController : Controller
88
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using ElectronNET.API;
7+
using ElectronNET.API.Entities;
8+
9+
namespace ElectronNET.WebApp.Controllers
10+
{
11+
public class WindowsController : Controller
12+
{
13+
public IActionResult Index()
14+
{
15+
string viewPath = $"http://localhost:{BridgeSettings.WebPort}/windows/demowindow";
16+
17+
Electron.IpcMain.On("new-window", async (args) => {
18+
19+
await Electron.WindowManager.CreateWindowAsync(viewPath);
20+
21+
});
22+
23+
Electron.IpcMain.On("manage-window", async (args) => {
24+
25+
var browserWindow = await Electron.WindowManager.CreateWindowAsync(viewPath);
26+
browserWindow.OnMove += UpdateReply;
27+
browserWindow.OnResize += UpdateReply;
28+
});
29+
30+
Electron.IpcMain.On("listen-to-window", async (args) => {
31+
var mainBrowserWindow = Electron.WindowManager.BrowserWindows.First();
32+
33+
var browserWindow = await Electron.WindowManager.CreateWindowAsync(viewPath);
34+
browserWindow.OnFocus += () => Electron.IpcMain.Send(mainBrowserWindow, "listen-to-window-focus");
35+
browserWindow.OnBlur += () => Electron.IpcMain.Send(mainBrowserWindow, "listen-to-window-blur");
36+
37+
Electron.IpcMain.On("listen-to-window-set-focus", (x) => browserWindow.Focus());
38+
});
39+
40+
Electron.IpcMain.On("frameless-window", async (args) => {
41+
var options = new BrowserWindowOptions
42+
{
43+
Frame = false
44+
};
45+
await Electron.WindowManager.CreateWindowAsync(options, viewPath);
46+
});
47+
48+
return View();
49+
}
50+
51+
private async void UpdateReply()
52+
{
53+
var browserWindow = Electron.WindowManager.BrowserWindows.Last();
54+
var size = await browserWindow.GetSizeAsync();
55+
var position = await browserWindow.GetPositionAsync();
56+
string message = $"Size: {size[0]},{size[1]} Position: {position[0]},{position[1]}";
57+
58+
var mainWindow = Electron.WindowManager.BrowserWindows.First();
59+
Electron.IpcMain.Send(mainWindow, "manage-window-reply", message);
60+
}
61+
62+
public IActionResult DemoWindow()
63+
{
64+
return View();
65+
}
66+
}
67+
}

ElectronNET-API-Demos/Controllers/MenusController.cs

+9-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
using ElectronNET.API.Entities;
44
using ElectronNET.API;
55

6-
namespace ElectronNET_API_Demos.Controllers
6+
namespace ElectronNET.WebApp.Controllers
77
{
88
public class MenusController : Controller
99
{
1010
public IActionResult Index()
1111
{
1212
if (HybridSupport.IsElectronActive)
1313
{
14+
Electron.App.Ready += () => CreateContextMenu();
15+
1416
var menu = new MenuItem[] {
15-
new MenuItem { Label = "Edit", Type = MenuType.submenu, Submenu = new MenuItem[] {
17+
new MenuItem { Label = "Edit", Submenu = new MenuItem[] {
1618
new MenuItem { Label = "Undo", Accelerator = "CmdOrCtrl+Z", Role = MenuRole.undo },
1719
new MenuItem { Label = "Redo", Accelerator = "Shift+CmdOrCtrl+Z", Role = MenuRole.redo },
1820
new MenuItem { Type = MenuType.separator },
@@ -22,7 +24,7 @@ public IActionResult Index()
2224
new MenuItem { Label = "Select All", Accelerator = "CmdOrCtrl+A", Role = MenuRole.selectall }
2325
}
2426
},
25-
new MenuItem { Label = "View", Type = MenuType.submenu, Submenu = new MenuItem[] {
27+
new MenuItem { Label = "View", Submenu = new MenuItem[] {
2628
new MenuItem
2729
{
2830
Label = "Reload",
@@ -76,12 +78,12 @@ public IActionResult Index()
7678
}
7779
}
7880
},
79-
new MenuItem { Label = "Window", Role = MenuRole.window, Type = MenuType.submenu, Submenu = new MenuItem[] {
81+
new MenuItem { Label = "Window", Role = MenuRole.window, Submenu = new MenuItem[] {
8082
new MenuItem { Label = "Minimize", Accelerator = "CmdOrCtrl+M", Role = MenuRole.minimize },
8183
new MenuItem { Label = "Close", Accelerator = "CmdOrCtrl+W", Role = MenuRole.close }
8284
}
8385
},
84-
new MenuItem { Label = "Help", Role = MenuRole.help, Type = MenuType.submenu, Submenu = new MenuItem[] {
86+
new MenuItem { Label = "Help", Role = MenuRole.help, Submenu = new MenuItem[] {
8587
new MenuItem
8688
{
8789
Label = "Learn More",
@@ -93,7 +95,6 @@ public IActionResult Index()
9395

9496
Electron.Menu.SetApplicationMenu(menu);
9597

96-
CreateContextMenu();
9798
}
9899

99100
return View();
@@ -112,10 +113,8 @@ private void CreateContextMenu()
112113
new MenuItem { Label = "Electron.NET", Type = MenuType.checkbox, Checked = true }
113114
};
114115

115-
Electron.App.BrowserWindowFocus += () => {
116-
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
117-
Electron.Menu.SetContextMenu(mainWindow, menu);
118-
};
116+
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
117+
Electron.Menu.SetContextMenu(mainWindow, menu);
119118

120119
Electron.IpcMain.On("show-context-menu", (args) =>
121120
{

ElectronNET-API-Demos/Controllers/NotificationsController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using ElectronNET.API;
33
using ElectronNET.API.Entities;
44

5-
namespace ElectronNET_API_Demos.Controllers
5+
namespace ElectronNET.WebApp.Controllers
66
{
77
public class NotificationsController : Controller
88
{

0 commit comments

Comments
 (0)