mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-20 15:46:15 +00:00
implement electron build with electron-packager into build.cmd and change the current root path from WebApp
This commit is contained in:
42
CLIDeploy/main.js
Normal file
42
CLIDeploy/main.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const { app, BrowserWindow, Notification } = require('electron');
|
||||
const io = require('socket.io')(3000);
|
||||
const path = require('path');
|
||||
|
||||
let window;
|
||||
let apiProcess;
|
||||
|
||||
app.on('ready', () => {
|
||||
const process = require('child_process').spawn;
|
||||
|
||||
// run server
|
||||
var apipath = path.join(__dirname, '..\\ElectronNET.WebApp\\bin\\dist\\win\\ElectronNET.WebApp.exe');
|
||||
apiProcess = process(apipath);
|
||||
|
||||
apiProcess.stdout.on('data', (data) => {
|
||||
var text = data.toString();
|
||||
console.log(`stdout: ${data.toString()}`);
|
||||
});
|
||||
});
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('ASP.NET Core Application connected...');
|
||||
|
||||
socket.on('createBrowserWindow', (options) => {
|
||||
console.log(options);
|
||||
options.show = true;
|
||||
|
||||
window = new BrowserWindow(options);
|
||||
window.loadURL('http://localhost:5000');
|
||||
|
||||
window.on('closed', function () {
|
||||
mainWindow = null;
|
||||
apiProcess = null;
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('createNotification', (options) => {
|
||||
const notification = new Notification(options);
|
||||
notification.show();
|
||||
});
|
||||
});
|
||||
|
||||
1411
CLIDeploy/package-lock.json
generated
Normal file
1411
CLIDeploy/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
CLIDeploy/package.json
Normal file
16
CLIDeploy/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "ElectronNET.Host",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"electron": "^1.7.8",
|
||||
"socket.io": "^2.0.3"
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ namespace ElectronNET.CLI.Commands
|
||||
Console.WriteLine("Install Electron Host...");
|
||||
|
||||
string currentPath = Directory.GetCurrentDirectory();
|
||||
|
||||
string targetPath = Path.Combine(currentPath, "..", "CLIDeploy");
|
||||
|
||||
Console.WriteLine("Target: " + targetPath);
|
||||
|
||||
@@ -76,6 +76,12 @@ namespace ElectronNET.CLI
|
||||
Console.WriteLine("\t");
|
||||
Console.WriteLine($"\t{StartElectronCommand.COMMAND_NAME.PadRight(NAME_WIDTH)} {StartElectronCommand.COMMAND_DESCRIPTION}");
|
||||
|
||||
Console.WriteLine("\t");
|
||||
Console.WriteLine("Commands to build the Electron Application:");
|
||||
Console.WriteLine("\t");
|
||||
Console.WriteLine($"\t{InstallElectronCommand.COMMAND_NAME.PadRight(NAME_WIDTH)} {InstallElectronCommand.COMMAND_DESCRIPTION}");
|
||||
|
||||
|
||||
Console.WriteLine("\t");
|
||||
Console.WriteLine("\t");
|
||||
Console.WriteLine("To get help on individual commands execute:");
|
||||
|
||||
@@ -9,7 +9,7 @@ app.on('ready', () => {
|
||||
const process = require('child_process').spawn;
|
||||
|
||||
// run server
|
||||
var apipath = path.join(__dirname, '..\\ElectronNET.WebApp\\bin\\dist\\win\\ElectronNET.WebApp.exe');
|
||||
var apipath = path.join(__dirname, '\\bin\\ElectronNET.WebApp.exe');
|
||||
apiProcess = process(apipath);
|
||||
|
||||
apiProcess.stdout.on('data', (data) => {
|
||||
@@ -40,3 +40,19 @@ io.on('connection', (socket) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (win === null) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
@@ -12,5 +12,6 @@
|
||||
"dependencies": {
|
||||
"electron": "^1.7.8",
|
||||
"socket.io": "^2.0.3"
|
||||
}
|
||||
},
|
||||
"devDependencies": {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace ElectronNET.WebApp
|
||||
{
|
||||
@@ -11,9 +11,11 @@ namespace ElectronNET.WebApp
|
||||
BuildWebHost(args).Run();
|
||||
}
|
||||
|
||||
// WICHTIG! UseContentRoot auf Assembly Ordner Essentiell!
|
||||
// Ggf. kann man via Parameter den Content Root durchreichen?
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseContentRoot(Path.Combine(Directory.GetCurrentDirectory(), "..", "ElectronNET.WebApp"))
|
||||
.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
|
||||
ASP.NET MVC core dependencies have been added to the project.
|
||||
(These dependencies include packages required to enable scaffolding)
|
||||
|
||||
However you may still need to do make changes to your project.
|
||||
|
||||
1. Suggested changes to Startup class:
|
||||
1.1 Add a constructor:
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
1.2 Add MVC services:
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add framework services.
|
||||
services.AddMvc();
|
||||
}
|
||||
|
||||
1.3 Configure web app to use use Configuration and use MVC routing:
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
echo Bundle ASP.NET Core Project into EXE
|
||||
|
||||
cd ElectronNET.WebApp
|
||||
dotnet restore
|
||||
dotnet publish -r win10-x64 --output bin/dist/win
|
||||
dotnet publish -r win10-x64 --output ../ElectronNET.Host/bin/
|
||||
|
||||
echo Start Electron with bundled EXE
|
||||
..\ElectronNET.Host\node_modules\.bin\electron.cmd "..\ElectronNET.Host\main.js"
|
||||
cd ..\ElectronNET.Host
|
||||
electron-packager . --platform=win32 --arch=x64 --out=../ElectronNET.WebApp/bin/desktop/ --overwrite
|
||||
9
start.cmd
Normal file
9
start.cmd
Normal file
@@ -0,0 +1,9 @@
|
||||
echo Bundle ASP.NET Core Project into EXE
|
||||
|
||||
cd ElectronNET.WebApp
|
||||
dotnet restore
|
||||
dotnet publish -r win10-x64 --output ../ElectronNET.Host/bin/
|
||||
|
||||
echo Start Electron with bundled EXE
|
||||
cd ..\ElectronNET.Host
|
||||
..\ElectronNET.Host\node_modules\.bin\electron.cmd "..\ElectronNET.Host\main.js"
|
||||
Reference in New Issue
Block a user