diff --git a/ElectronNET.Host/.vscode/launch.json b/ElectronNET.Host/.vscode/launch.json new file mode 100644 index 0000000..30c21a7 --- /dev/null +++ b/ElectronNET.Host/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Electron App", + "program": "${workspaceFolder}\\main.js", + "runtimeExecutable": "${workspaceFolder}\\node_modules\\.bin\\electron" + } + ] +} \ No newline at end of file diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index daadd08..1467313 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -1,22 +1,27 @@ const { app, BrowserWindow, Notification } = require('electron'); const io = require('socket.io')(3000); +const fs = require('fs'); const path = require('path'); - +const process = require('child_process').spawn; let window; let apiProcess; app.on('ready', () => { - const process = require('child_process').spawn; // run server - // ToDo: The .exe name may vary. The most simple solution would be to locate the first .exe in the given directory - var apipath = path.join(__dirname, '\\bin\\ElectronNET.WebApp.exe'); - apiProcess = process(apipath); + var binPath = path.join(__dirname, 'bin'); + fs.readdir(binPath, (error, files) => { + const exeFiles = files.filter((name) => name.indexOf('.exe') > -1); + const exeFileName = exeFiles[0]; + const apipath = path.join(binPath, exeFileName); + apiProcess = process(apipath); - apiProcess.stdout.on('data', (data) => { - var text = data.toString(); - console.log(`stdout: ${data.toString()}`); + apiProcess.stdout.on('data', (data) => { + var text = data.toString(); + console.log(`stdout: ${data.toString()}`); + }); }); + }); io.on('connection', (socket) => {