launcher: launch server with fork instead of spawn

server: let the launcher apply config file updates
This commit is contained in:
bordun 2020-12-04 01:22:31 +01:00
parent 8f266ae70a
commit 6f8fd92e49
3 changed files with 41 additions and 8 deletions

View file

@ -6,7 +6,8 @@
- editor: cloned `dropdown` and `input` widgets not opening when selected
- widgets: prevent value-stateless widgets (tap buttons, clone, scripts, html and svg) from sending a value for cross-client synchronization (leads to unexpected script execution) and exclude them from state saves
- input: apply `decimals` number before checking the value against the `validation` expression
- range: `steps` and `dashed` property not working; remove `origin` property
- range: `steps` and `dashed` property not working; remove `origin` property
- config conflicts between launcher and server (affecting at least session history)
## 1.7.3

View file

@ -108,7 +108,7 @@ if (settings.cli) {
path = require('path'),
address = 'file://' + path.resolve(__dirname + '/../launcher/' + 'index.html'),
{ipcMain} = require('electron'),
{spawn} = require('child_process'),
{fork} = require('child_process'),
launcher
process.on('exit',()=>{
@ -152,7 +152,7 @@ if (settings.cli) {
ipcMain.on('start',function(e, options){
var args = ['--', app.getAppPath(), '--no-gui']
var args = ['--no-gui']
// if (process.platform === 'win32') args.unshift('--') // not needed with ELECTRON_RUN_AS_NODE since '--' is always prepended
for (var k in settings.read('options')) {
@ -165,7 +165,7 @@ if (settings.cli) {
}
}
global.serverProcess = spawn(process.argv[0], args, {stdio: 'pipe', env: {...process.env, 'ELECTRON_RUN_AS_NODE':'1'}})
global.serverProcess = fork(app.getAppPath(), args, {stdio: 'pipe', env: process.env})
launcher.webContents.send('server-started')
if (!settings.read('no-gui')) {
@ -186,6 +186,15 @@ if (settings.cli) {
console.error(String(data).trim())
})
global.serverProcess.on('message', (data) => {
var [command, args] = data
if (command === 'settings.write') {
settings.write(args[0], args[1], false)
}
})
global.serverProcess.on('close', (code) => {
console.log('(INFO) Server stopped')
global.serverProcess = null

View file

@ -148,11 +148,23 @@ module.exports = {
if (!tmp && configPathExists) {
config[key] = value
fs.writeFile(configPath, JSON.stringify(config, null, 4), function(err, data) {
if (err) throw err
})
if (process.send) {
// server running as child process of launcher
// -> just pass the modification to the launcher process
process.send(['settings.write', [key, value]])
} else {
config[key] = value
fs.writeFile(configPath, JSON.stringify(config, null, 4), function(err, data) {
if (err) throw err
})
}
}
// we are in launcher process -> update server process' config
if (global.serverProcess) {
global.serverProcess.send(['settings.write', [key, value]])
}
},
@ -161,3 +173,14 @@ module.exports = {
infos: infos,
appAddresses: ()=>address(module.exports.read('use-ssl') ? 'https://' : 'http://', settings.options.port || 8080)
}
if (process.send) {
// server running as child process of launcher
// update local config when the main config is modified
process.on('message', function(data) {
var [command, args] = data
if (command === 'settings.write') {
module.exports.write(args[0], args[1], true)
}
})
}