From f2fe86c250f5039261338c456aa2a01634703cde Mon Sep 17 00:00:00 2001 From: Gregor Biswanger Date: Sun, 15 Oct 2017 21:56:56 +0200 Subject: [PATCH] implement execute binary file from manifest json file config --- ElectronNET.Host/main.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 51db14f..5b2e0c1 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -1,5 +1,4 @@ const { app, BrowserWindow, Notification } = require('electron'); -const fs = require('fs'); const path = require('path'); const process = require('child_process').spawn; const portfinder = require('detect-port'); @@ -44,23 +43,22 @@ function startSocketApiBridge(port) { function startAspCoreBackend(electronPort) { portfinder(8000, (error, electronWebPort) => { loadURL = `http://localhost:${electronWebPort}` - const arguments = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`]; + const parameters = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`]; - var binPath = path.join(__dirname, 'bin'); - fs.readdir(binPath, (error, files) => { + const manifestFile = require("./bin/electronnet.json"); + let binaryFile = manifestFile.executable; + + const os = require("os"); + if(os.platform() === "win32") { + binaryFile = binaryFile + '.exe'; + } + + const binFilePath = path.join(__dirname, 'bin', binaryFile); + apiProcess = process(binFilePath, parameters); - // ToDo: Read 'electronnet.json and use the exectuable' - // add '.exe' to the exectuable name on windows and leave as is on linux/mac and we are done - - const exeFiles = files.filter((name) => name.indexOf('.exe') > -1); - const exeFileName = exeFiles[0]; - const apipath = path.join(binPath, exeFileName); - apiProcess = process(apipath, arguments); - - 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()}`); }); }); }