michalzaq12 / xpda-dev

Cross platform desktop app development tools

Home Page:https://www.npmjs.com/package/@xpda-dev/core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Electron is not propely killed when relaunching

maxerbox opened this issue · comments

Node 12.
Electron 8.
Under electron-nuxt 1.6.0.
OS : Debian bulleyes.

When relaunching electron, due to editing a file in electron-nuxt, electron is not properly killed, leaving a blank window and a new window is created.

Use the patch-package to patch code:

filename: @xpda-dev+electron-launcher+0.3.0.patch

diff --git a/node_modules/@xpda-dev/electron-launcher/lib/ElectronLauncher.js b/node_modules/@xpda-dev/electron-launcher/lib/ElectronLauncher.js
index 941fb90..29e0c16 100644
--- a/node_modules/@xpda-dev/electron-launcher/lib/ElectronLauncher.js
+++ b/node_modules/@xpda-dev/electron-launcher/lib/ElectronLauncher.js
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
 const child_process_1 = require("child_process");
 const events_1 = require("events");
 const core_1 = require("@xpda-dev/core");
-const { killWithAllSubProcess } = core_1.utils;
+const { killProcess } = core_1.utils;
 class ElectronLauncher extends events_1.EventEmitter {
     constructor(options) {
         super();
@@ -27,7 +27,7 @@ class ElectronLauncher extends events_1.EventEmitter {
     launch() {
         return __awaiter(this, void 0, void 0, function* () {
             let args = [`--inspect=${this.inspectionPort}`, this.entryFile, '--auto-detect=false', '--no-proxy-server', ...this.electronOptions];
-            this.process = child_process_1.spawn(this.electronPath, args);
+            this.process = child_process_1.spawn(this.electronPath, args, { detached: false });
             this.pipe(this.logger);
             this.process.on('exit', code => {
                 if (code === this.relaunchCode)
@@ -54,7 +54,9 @@ class ElectronLauncher extends events_1.EventEmitter {
                 return;
             this.emit('relaunch');
             yield this.exit();
-            this.launch();
+            setTimeout(() => {
+                this.launch();
+            }, 500);
         });
     }
     exit() {
@@ -64,7 +66,7 @@ class ElectronLauncher extends events_1.EventEmitter {
             this.process.removeAllListeners('exit');
             this.process.stdout.end();
             this.process.stderr.end();
-            yield killWithAllSubProcess(this.pid, this.logger.error.bind(this.logger));
+            yield killProcess(this.pid, this.logger.error.bind(this.logger));
             this.process = null;
         });
     }