关于通过child_process 启动 的 electron 进程结束后窗体不关闭
在修改一个create-react-app+electron 的 rep 想添加一个监听文件重新运行 electron的功能,但是通过child_process启动的 electron 在结束子进程后窗体内容消失,但是窗体后并没有关闭, 还是我理解有问题吗… 求教谢谢大家! 使用 respawn 是想保证 子进程完全结束后再重新启动 lib 还是通过 child_process去执行 我的代码rep
const net = require('net');
const port = process.env.PORT ? (process.env.PORT - 100) : 3000;
const watch = require('node-watch');
const watcher = watch('./', { recursive: true });
const respawn = require('respawn')
require('events').EventEmitter.prototype._maxListeners = 100;
process.env.ELECTRON_START_URL = `http://localhost:${port}`;
const client = new net.Socket();
let startedElectron = false;
const tryConnection = () => client.connect({port: port}, () => {
client.end();
if(!startedElectron) {
console.log('starting electron');
startedElectron = true;
//启动命令 electron 对应的是 electron .
const runner = respawn(['npm','run', 'electron']);
runner.start()
runner.on('stdout', (data)=>{
console.log(data.toString());
});
runner.on('stderr', (data)=>{
console.error(data.toString());
});
console.log('starting watching');
watcher.on('change', function(evt, name) {
console.log("runner restart")
//原进程结束后 重新调起
runner.stop(()=>runner.start())
});
watcher.on('error', function(err) {
console.log(`${evt}`);
});
}
}
);
tryConnection();
client.on('error', (error) => {
setTimeout(tryConnection, 1000);
});
结果 旧窗体依然在 , electron