diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index a50a191..ce128bb 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -12,7 +12,7 @@ namespace ElectronNET.API private readonly Socket _socket; private readonly JsonSerializer _jsonSerializer; - public App(int width, int height) + public App(int width, int height, bool show) { _jsonSerializer = new JsonSerializer() { @@ -26,7 +26,8 @@ namespace ElectronNET.API var browserWindowOptions = new BrowserWindowOptions() { Height = height, - Width = width + Width = width, + Show = show }; socket.Emit("createBrowserWindow", JObject.FromObject(browserWindowOptions, _jsonSerializer)); diff --git a/ElectronNET.API/ElectronNET.API.csproj b/ElectronNET.API/ElectronNET.API.csproj index 795112e..a7695f6 100644 --- a/ElectronNET.API/ElectronNET.API.csproj +++ b/ElectronNET.API/ElectronNET.API.csproj @@ -1,7 +1,7 @@ - netcoreapp1.1 + netcoreapp2.0 diff --git a/ElectronNET.Host/.vscode/launch.json b/ElectronNET.Host/.vscode/launch.json new file mode 100644 index 0000000..1ec14a2 --- /dev/null +++ b/ElectronNET.Host/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Electron App", + "cwd": "${workspaceRoot}", + "runtimeExecutable": "${workspaceRoot}\\node_modules\\.bin\\electron.cmd", + "program": "${workspaceRoot}\\main.js" + } + ] + } \ No newline at end of file diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 781301f..44bd0e2 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -1,19 +1,36 @@ -// const { app, BrowserWindow } = require('electron'); +const { app, BrowserWindow } = require('electron'); const io = require('socket.io')(3000); +const path = require('path'); -// let window; +let window; +let apiProcess; -// app.on('ready', () => { +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) => { + console.log(`stdout: ${data}`); + }); +}); io.on('connection', (socket) => { console.log('a user 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; + }); }); }); diff --git a/ElectronNET.Host/package.json b/ElectronNET.Host/package.json index 7783d0e..7f50320 100644 --- a/ElectronNET.Host/package.json +++ b/ElectronNET.Host/package.json @@ -2,7 +2,7 @@ "name": "ElectronNET.Host", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "main.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/ElectronNET.WebApp/ElectronNET.WebApp.csproj b/ElectronNET.WebApp/ElectronNET.WebApp.csproj index be123bd..810cecd 100644 --- a/ElectronNET.WebApp/ElectronNET.WebApp.csproj +++ b/ElectronNET.WebApp/ElectronNET.WebApp.csproj @@ -1,7 +1,8 @@ - netcoreapp1.1 + netcoreapp2.0 + win10-x64 @@ -9,8 +10,7 @@ - - + diff --git a/ElectronNET.WebApp/Program.cs b/ElectronNET.WebApp/Program.cs index edd6c39..d22b8e4 100644 --- a/ElectronNET.WebApp/Program.cs +++ b/ElectronNET.WebApp/Program.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using System.Net.Sockets; -using System.Net; -using System.Text; -using System.Diagnostics; namespace ElectronNET.WebApp { @@ -15,15 +7,12 @@ namespace ElectronNET.WebApp { public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseStartup() - .UseApplicationInsights() - .Build(); - - host.Run(); + BuildWebHost(args).Run(); } + + public static IWebHost BuildWebHost(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup() + .Build(); } } diff --git a/ElectronNET.WebApp/Startup.cs b/ElectronNET.WebApp/Startup.cs index 5ef9d19..33b75e2 100644 --- a/ElectronNET.WebApp/Startup.cs +++ b/ElectronNET.WebApp/Startup.cs @@ -13,6 +13,7 @@ namespace ElectronNET.WebApp // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + //services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -30,7 +31,7 @@ namespace ElectronNET.WebApp await context.Response.WriteAsync("Hello World!"); }); - var electronApp = new App(800, 600); + var electronApp = new App(800, 600, true); } } }