I have created an electron app which when run in the main process will spawn a node child process which will serve some html content.
app.on('ready', () => {
//check for port 80
const port = 80;
find('port', port)
.then(function (list) {
if (!list.length) {
console.log('port 80 is free now');
// in development show command prompt
let options = {shell: true, detached: isDevelopment}, path = '';
try {
if (win32) { path = rccServerPathWin32 }
else if(macOS){ path = rccServerPathMacOS }
console.log(path)
if (fs.existsSync(path)) {
serverProcess = child_process.execFile(path, ['/desktopmode'], options);
mainWindow = createMainWindow();
// Execute this once DOM is ready
socket = io(localRcc);
feathersjsApp = feathers();
feathersjsApp.configure(socketio(socket));
} else {
mainWindow = createMainWindowErrorPage();
}
} catch (err) {
console.error(err)
}
} else {
console.log('%s is listening port 80', list[0]);
// TODO Display page contains information what is currently occupied this port
mainWindow = createMainWindowErrorPage();
}
})
})
I use the following settings to build and package the app:
"scripts": {
"start": "NODE_ENV=dev && electron .",
"dist": "electron-builder",
"dist-win": "electron-builder --win portable",
"dist-mac": "electron-builder --mac",
"dist-linux": "electron-builder --linux snap"
},
"build": {
"extraResources": [{
"from": "server",
"to": "server"
}]
},
server is the directory where I have my node process, which I expect to be build in the Resources directory when I build the app for MacOS. Now the problem comes when I run the app. If I open the package and run the app from the executable file located in Contents/MacOS/'nameOfProgram' then it would start the app and run the child process. But if I try running the app from the package icon for example in Applications folder it won't start the child process. It starts a blank client and will not even show the default html for the electron app.