From fdbb824b23b1983ec4253158e9c153663a21283e Mon Sep 17 00:00:00 2001 From: Philippe Gibert Date: Sun, 7 Feb 2021 21:31:47 +0100 Subject: [PATCH 1/4] Kill Http server on app quit event --- app/main/server.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/main/server.js b/app/main/server.js index e433c103..c53124df 100644 --- a/app/main/server.js +++ b/app/main/server.js @@ -1,3 +1,4 @@ +const { app } = require("electron"); const { fork } = require("child_process"); const { watch } = require("../utils"); const quit = require("./quit"); @@ -43,6 +44,10 @@ function start(onStared = null) { server.on("message", (message) => { if (message === "started") onStared(); }); + + + // Kill Server on app Quit + app.on("quit", () => stop()); } function restart() { From 402e18541771d1968a2f93ee1e3af757a69576df Mon Sep 17 00:00:00 2001 From: skarab42 Date: Wed, 10 Feb 2021 16:39:39 +0100 Subject: [PATCH 2/4] docs: Remove comment --- app/main/server.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/main/server.js b/app/main/server.js index c53124df..63a1605a 100644 --- a/app/main/server.js +++ b/app/main/server.js @@ -45,8 +45,6 @@ function start(onStared = null) { if (message === "started") onStared(); }); - - // Kill Server on app Quit app.on("quit", () => stop()); } From 6b00485729aea55f0e111c3636f9cbea32db58bd Mon Sep 17 00:00:00 2001 From: skarab42 Date: Wed, 10 Feb 2021 17:03:53 +0100 Subject: [PATCH 3/4] refacto: Move app quit listener --- app/main/index.js | 3 ++- app/main/server.js | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/main/index.js b/app/main/index.js index 0a93ce0e..8c2ef5ac 100644 --- a/app/main/index.js +++ b/app/main/index.js @@ -24,5 +24,6 @@ function init() { } app.requestSingleInstanceLock() ? init() : app.quit(); - app.on("second-instance", () => mainWindow()); + +app.on("quit", () => server.stop()); diff --git a/app/main/server.js b/app/main/server.js index 63a1605a..e433c103 100644 --- a/app/main/server.js +++ b/app/main/server.js @@ -1,4 +1,3 @@ -const { app } = require("electron"); const { fork } = require("child_process"); const { watch } = require("../utils"); const quit = require("./quit"); @@ -44,8 +43,6 @@ function start(onStared = null) { server.on("message", (message) => { if (message === "started") onStared(); }); - - app.on("quit", () => stop()); } function restart() { From 966d76ecfb1947df7a9eb4b8274b83c1a1b67184 Mon Sep 17 00:00:00 2001 From: skarab42 Date: Wed, 10 Feb 2021 17:04:30 +0100 Subject: [PATCH 4/4] feat: Add SIGINT|TERM|KILL listeners --- app/main/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/main/index.js b/app/main/index.js index 8c2ef5ac..781f02f5 100644 --- a/app/main/index.js +++ b/app/main/index.js @@ -27,3 +27,6 @@ app.requestSingleInstanceLock() ? init() : app.quit(); app.on("second-instance", () => mainWindow()); app.on("quit", () => server.stop()); +process.on("SIGINT", () => server.stop()); +process.on("SIGTERM", () => server.stop()); +process.on("SIGKILL", () => server.stop());