Skip to content

Commit

Permalink
Migrate to .NET 6 and Electron.NET 23.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorBiswanger committed Mar 27, 2023
1 parent 3e27644 commit 046a171
Show file tree
Hide file tree
Showing 40 changed files with 6,971 additions and 188 deletions.
82 changes: 82 additions & 0 deletions AnalysisReport.sarif
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "Dependency Analysis",
"semanticVersion": "0.4.355802",
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview",
"rules": [
{
"id": "UA106",
"name": "PackageToBeAdded",
"fullDescription": {
"text": "Packages that need to be added in order to upgrade the project to chosen TFM"
},
"helpUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
}
]
}
},
"results": [
{
"ruleId": "UA106",
"message": {
"text": "Package Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.4.410601 needs to be added."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/Users/Gregor/source/repos/electron.net-api-demos/ElectronNET-API-Demos/ElectronNET-API-Demos.csproj"
},
"region": {}
}
}
]
},
{
"ruleId": "UA106",
"message": {
"text": "Package Microsoft.AspNetCore.Mvc.NewtonsoftJson, Version=7.0.4 needs to be added."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/Users/Gregor/source/repos/electron.net-api-demos/ElectronNET-API-Demos/ElectronNET-API-Demos.csproj"
},
"region": {}
}
}
]
}
],
"columnKind": "utf16CodeUnits"
},
{
"tool": {
"driver": {
"name": "API Upgradability",
"semanticVersion": "0.4.355802",
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
}
},
"results": [],
"columnKind": "utf16CodeUnits"
},
{
"tool": {
"driver": {
"name": "Component Analysis",
"semanticVersion": "0.4.355802",
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
}
},
"results": [],
"columnKind": "utf16CodeUnits"
}
]
}
2 changes: 1 addition & 1 deletion ElectronNET-API-Demos/Controllers/AboutController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class AboutController : Controller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using ElectronNET.API;
using ElectronNET.API.Entities;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class AppSysInformationController : Controller
{
Expand All @@ -21,7 +21,7 @@ public IActionResult Index()

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

var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "got-sys-info", homePath);
Expand Down
22 changes: 20 additions & 2 deletions ElectronNET-API-Demos/Controllers/ClipboardController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Drawing;
using System.IO;
using Microsoft.AspNetCore.Mvc;
using ElectronNET.API;
using System.Linq;
using ElectronNET.API.Entities;
using Newtonsoft.Json;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class ClipboardController : Controller
{
Expand All @@ -23,6 +28,19 @@ public IActionResult Index()
var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "paste-from", pasteText);
});

Electron.IpcMain.On("copy-image-to", (test) =>
{
var nativeImage = NativeImage.CreateFromDataURL(test.ToString());
Electron.Clipboard.WriteImage(nativeImage);
});

Electron.IpcMain.On("paste-image-to", async test =>
{
var nativeImage = await Electron.Clipboard.ReadImageAsync();
var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "paste-image-from", JsonConvert.SerializeObject(nativeImage));
});
}

return View();
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET-API-Demos/Controllers/CrashHangController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using ElectronNET.API;
using ElectronNET.API.Entities;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class CrashHangController : Controller
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class DesktopCapturerController : Controller
{
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET-API-Demos/Controllers/DialogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using ElectronNET.API;
using ElectronNET.API.Entities;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class DialogsController : Controller
{
Expand Down
38 changes: 37 additions & 1 deletion ElectronNET-API-Demos/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
using Microsoft.AspNetCore.Mvc;
using ElectronNET.API;
using System;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
if (HybridSupport.IsElectronActive)
{
Electron.PowerMonitor.OnLockScreen += () =>
{
Console.WriteLine("Screen Locked detected from C#");
};

Electron.PowerMonitor.OnUnLockScreen += () =>
{
Console.WriteLine("Screen unlocked detected from C# ");
};

Electron.PowerMonitor.OnSuspend += () =>
{
Console.WriteLine("The system is going to sleep");
};

Electron.PowerMonitor.OnResume += () =>
{
Console.WriteLine("The system is resuming");
};

Electron.PowerMonitor.OnAC += () =>
{
Console.WriteLine("The system changes to AC power");
};

Electron.PowerMonitor.OnBattery += () =>
{
Console.WriteLine("The system is about to change to battery power");
};

}

return View();
}
}
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET-API-Demos/Controllers/HostHookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class HostHookController : Controller
{
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET-API-Demos/Controllers/IpcController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using ElectronNET.API;
using System.Linq;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class IpcController : Controller
{
Expand Down
67 changes: 67 additions & 0 deletions ElectronNET-API-Demos/Controllers/ManageWindowsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ElectronNET.API;
using ElectronNET.API.Entities;

namespace ElectronNET.WebApp.Controllers
{
public class WindowsController : Controller
{
public IActionResult Index()
{
string viewPath = $"http://localhost:{BridgeSettings.WebPort}/windows/demowindow";

Electron.IpcMain.On("new-window", async (args) => {

await Electron.WindowManager.CreateWindowAsync(viewPath);

});

Electron.IpcMain.On("manage-window", async (args) => {

var browserWindow = await Electron.WindowManager.CreateWindowAsync(viewPath);
browserWindow.OnMove += UpdateReply;
browserWindow.OnResize += UpdateReply;
});

Electron.IpcMain.On("listen-to-window", async (args) => {
var mainBrowserWindow = Electron.WindowManager.BrowserWindows.First();

var browserWindow = await Electron.WindowManager.CreateWindowAsync(viewPath);
browserWindow.OnFocus += () => Electron.IpcMain.Send(mainBrowserWindow, "listen-to-window-focus");
browserWindow.OnBlur += () => Electron.IpcMain.Send(mainBrowserWindow, "listen-to-window-blur");

Electron.IpcMain.On("listen-to-window-set-focus", (x) => browserWindow.Focus());
});

Electron.IpcMain.On("frameless-window", async (args) => {
var options = new BrowserWindowOptions
{
Frame = false
};
await Electron.WindowManager.CreateWindowAsync(options, viewPath);
});

return View();
}

private async void UpdateReply()
{
var browserWindow = Electron.WindowManager.BrowserWindows.Last();
var size = await browserWindow.GetSizeAsync();
var position = await browserWindow.GetPositionAsync();
string message = $"Size: {size[0]},{size[1]} Position: {position[0]},{position[1]}";

var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "manage-window-reply", message);
}

public IActionResult DemoWindow()
{
return View();
}
}
}
19 changes: 9 additions & 10 deletions ElectronNET-API-Demos/Controllers/MenusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
using ElectronNET.API.Entities;
using ElectronNET.API;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class MenusController : Controller
{
public IActionResult Index()
{
if (HybridSupport.IsElectronActive)
{
Electron.App.Ready += () => CreateContextMenu();

var menu = new MenuItem[] {
new MenuItem { Label = "Edit", Type = MenuType.submenu, Submenu = new MenuItem[] {
new MenuItem { Label = "Edit", Submenu = new MenuItem[] {
new MenuItem { Label = "Undo", Accelerator = "CmdOrCtrl+Z", Role = MenuRole.undo },
new MenuItem { Label = "Redo", Accelerator = "Shift+CmdOrCtrl+Z", Role = MenuRole.redo },
new MenuItem { Type = MenuType.separator },
Expand All @@ -22,7 +24,7 @@ public IActionResult Index()
new MenuItem { Label = "Select All", Accelerator = "CmdOrCtrl+A", Role = MenuRole.selectall }
}
},
new MenuItem { Label = "View", Type = MenuType.submenu, Submenu = new MenuItem[] {
new MenuItem { Label = "View", Submenu = new MenuItem[] {
new MenuItem
{
Label = "Reload",
Expand Down Expand Up @@ -76,12 +78,12 @@ public IActionResult Index()
}
}
},
new MenuItem { Label = "Window", Role = MenuRole.window, Type = MenuType.submenu, Submenu = new MenuItem[] {
new MenuItem { Label = "Window", Role = MenuRole.window, Submenu = new MenuItem[] {
new MenuItem { Label = "Minimize", Accelerator = "CmdOrCtrl+M", Role = MenuRole.minimize },
new MenuItem { Label = "Close", Accelerator = "CmdOrCtrl+W", Role = MenuRole.close }
}
},
new MenuItem { Label = "Help", Role = MenuRole.help, Type = MenuType.submenu, Submenu = new MenuItem[] {
new MenuItem { Label = "Help", Role = MenuRole.help, Submenu = new MenuItem[] {
new MenuItem
{
Label = "Learn More",
Expand All @@ -93,7 +95,6 @@ public IActionResult Index()

Electron.Menu.SetApplicationMenu(menu);

CreateContextMenu();
}

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

Electron.App.BrowserWindowFocus += () => {
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
Electron.Menu.SetContextMenu(mainWindow, menu);
};
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
Electron.Menu.SetContextMenu(mainWindow, menu);

Electron.IpcMain.On("show-context-menu", (args) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using ElectronNET.API;
using ElectronNET.API.Entities;

namespace ElectronNET_API_Demos.Controllers
namespace ElectronNET.WebApp.Controllers
{
public class NotificationsController : Controller
{
Expand Down
Loading

0 comments on commit 046a171

Please sign in to comment.