Skip to content

Commit edee1d4

Browse files
Update to .NET Core 3.1 and to Electron.NET 8.31.1
1 parent 745a0a8 commit edee1d4

35 files changed

+635
-144
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using ElectronNET.API;
2+
using ElectronNET.API.Entities;
3+
using Microsoft.AspNetCore.Mvc;
4+
using System.Linq;
5+
6+
namespace ElectronNET_API_Demos.Controllers
7+
{
8+
public class HostHookController : Controller
9+
{
10+
public IActionResult Index()
11+
{
12+
if (HybridSupport.IsElectronActive)
13+
{
14+
Electron.IpcMain.On("start-hoosthook", async (args) =>
15+
{
16+
var mainWindow = Electron.WindowManager.BrowserWindows.First();
17+
var options = new OpenDialogOptions
18+
{
19+
Properties = new OpenDialogProperty[]
20+
{
21+
OpenDialogProperty.openDirectory
22+
}
23+
};
24+
var folderPath = await Electron.Dialog.ShowOpenDialogAsync(mainWindow, options);
25+
26+
var resultFromTypeScript = await Electron.HostHook.CallAsync<string>("create-excel-file", folderPath);
27+
Electron.IpcMain.Send(mainWindow, "excel-file-created", resultFromTypeScript);
28+
});
29+
}
30+
31+
return View();
32+
}
33+
}
34+
}

ElectronNET-API-Demos/Controllers/MenusController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public IActionResult Index()
3131
{
3232
// on reload, start fresh and close any old
3333
// open secondary windows
34+
var mainWindowId = Electron.WindowManager.BrowserWindows.ToList().First().Id;
3435
Electron.WindowManager.BrowserWindows.ToList().ForEach(browserWindow => {
35-
if(browserWindow.Id != 1)
36+
if(browserWindow.Id != mainWindowId)
3637
{
3738
browserWindow.Close();
3839
}
@@ -111,7 +112,9 @@ private void CreateContextMenu()
111112
new MenuItem { Label = "Electron.NET", Type = MenuType.checkbox, Checked = true }
112113
};
113114

114-
var mainWindow = Electron.WindowManager.BrowserWindows.First();
115+
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
116+
if (mainWindow == null) return;
117+
115118
Electron.Menu.SetContextMenu(mainWindow, menu);
116119

117120
Electron.IpcMain.On("show-context-menu", (args) =>

ElectronNET-API-Demos/Controllers/NotificationsController.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
62
using ElectronNET.API;
73
using ElectronNET.API.Entities;
84

ElectronNET-API-Demos/Controllers/ProgressBarController.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

ElectronNET-API-Demos/Controllers/ShortcutsController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Threading.Tasks;
2-
using ElectronNET.API;
1+
using ElectronNET.API;
32
using ElectronNET.API.Entities;
43
using Microsoft.AspNetCore.Mvc;
4+
using System.Threading.Tasks;
55

66
namespace ElectronNET_API_Demos.Controllers
77
{
@@ -21,7 +21,6 @@ public IActionResult Index()
2121

2222
await Electron.Dialog.ShowMessageBoxAsync(options);
2323
});
24-
2524
Electron.App.WillQuit += arg => Task.Run(() => Electron.GlobalShortcut.UnregisterAll());
2625
}
2726

ElectronNET-API-Demos/Controllers/TrayController.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System.IO;
2+
using Microsoft.AspNetCore.Mvc;
23
using ElectronNET.API;
34
using ElectronNET.API.Entities;
5+
using Microsoft.AspNetCore.Hosting;
46

57
namespace ElectronNET_API_Demos.Controllers
68
{
79
public class TrayController : Controller
810
{
11+
private readonly IWebHostEnvironment _env;
12+
13+
public TrayController(IWebHostEnvironment env)
14+
{
15+
_env = env;
16+
}
17+
18+
919
public IActionResult Index()
1020
{
1121
if (HybridSupport.IsElectronActive)
@@ -21,7 +31,7 @@ public IActionResult Index()
2131
Click = () => Electron.Tray.Destroy()
2232
};
2333

24-
Electron.Tray.Show("/Assets/electron_32x32.png", menu);
34+
Electron.Tray.Show(Path.Combine(_env.ContentRootPath, "Assets/electron_32x32.png"), menu);
2535
Electron.Tray.SetToolTip("Electron Demo in the tray.");
2636
}
2737
else
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Linq;
2+
using ElectronNET.API;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace ElectronNET_API_Demos.Controllers
6+
{
7+
public class UpdateController : Controller
8+
{
9+
public IActionResult Index()
10+
{
11+
if (HybridSupport.IsElectronActive)
12+
{
13+
Electron.AutoUpdater.OnError += (message) => Electron.Dialog.ShowErrorBox("Error", message);
14+
Electron.AutoUpdater.OnCheckingForUpdate += async () => await Electron.Dialog.ShowMessageBoxAsync("Checking for Update");
15+
Electron.AutoUpdater.OnUpdateNotAvailable += async (info) => await Electron.Dialog.ShowMessageBoxAsync("Update not available");
16+
Electron.AutoUpdater.OnUpdateAvailable += async (info) => await Electron.Dialog.ShowMessageBoxAsync("Update available" + info.Version);
17+
Electron.AutoUpdater.OnDownloadProgress += (info) =>
18+
{
19+
var message1 = "Download speed: " + info.BytesPerSecond + "\n<br/>";
20+
var message2 = "Downloaded " + info.Percent + "%" + "\n<br/>";
21+
var message3 = $"({info.Transferred}/{info.Total})" + "\n<br/>";
22+
var message4 = "Progress: " + info.Progress + "\n<br/>";
23+
var information = message1 + message2 + message3 + message4;
24+
25+
var mainWindow = Electron.WindowManager.BrowserWindows.First();
26+
Electron.IpcMain.Send(mainWindow, "auto-update-reply", information);
27+
};
28+
Electron.AutoUpdater.OnUpdateDownloaded += async (info) => await Electron.Dialog.ShowMessageBoxAsync("Update complete!" + info.Version);
29+
30+
Electron.IpcMain.On("auto-update", async (args) =>
31+
{
32+
// Electron.NET CLI Command for deploy:
33+
// electronize build /target win /electron-params --publish=always
34+
35+
var currentVersion = await Electron.App.GetVersionAsync();
36+
var updateCheckResult = await Electron.AutoUpdater.CheckForUpdatesAndNotifyAsync();
37+
var availableVersion = updateCheckResult.UpdateInfo.Version;
38+
string information = $"Current version: {currentVersion} - available version: {availableVersion}";
39+
40+
var mainWindow = Electron.WindowManager.BrowserWindows.First();
41+
Electron.IpcMain.Send(mainWindow, "auto-update-reply", information);
42+
});
43+
}
44+
45+
return View();
46+
}
47+
}
48+
}

ElectronNET-API-Demos/Controllers/WindowsController.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ public IActionResult Index()
1515

1616
Electron.IpcMain.On("new-window", async (args) =>
1717
{
18-
1918
await Electron.WindowManager.CreateWindowAsync(viewPath);
20-
2119
});
2220

2321
Electron.IpcMain.On("manage-window", async (args) =>
2422
{
25-
2623
var browserWindow = await Electron.WindowManager.CreateWindowAsync(viewPath);
2724
browserWindow.OnMove += UpdateReply;
2825
browserWindow.OnResize += UpdateReply;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
# Created by https://www.gitignore.io/api/node
3+
# Edit at https://www.gitignore.io/?templates=node
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
14+
# Diagnostic reports (https://nodejs.org/api/report.html)
15+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
16+
17+
# Runtime data
18+
pids
19+
*.pid
20+
*.seed
21+
*.pid.lock
22+
23+
# Directory for instrumented libs generated by jscoverage/JSCover
24+
lib-cov
25+
26+
# Coverage directory used by tools like istanbul
27+
coverage
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
node_modules/
46+
jspm_packages/
47+
48+
# TypeScript v1 declaration files
49+
typings/
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional REPL history
58+
.node_repl_history
59+
60+
# Output of 'npm pack'
61+
*.tgz
62+
63+
# Yarn Integrity file
64+
.yarn-integrity
65+
66+
# dotenv environment variables file
67+
.env
68+
.env.test
69+
70+
# parcel-bundler cache (https://parceljs.org/)
71+
.cache
72+
73+
# next.js build output
74+
.next
75+
76+
# nuxt.js build output
77+
.nuxt
78+
79+
# vuepress build output
80+
.vuepress/dist
81+
82+
# Serverless directories
83+
.serverless/
84+
85+
# FuseBox cache
86+
.fusebox/
87+
88+
# DynamoDB Local files
89+
.dynamodb/
90+
91+
# End of https://www.gitignore.io/api/node

ElectronNET-API-Demos/ElectronHostHook/connector.js

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)