From 522ed1c99211c1fe252a57f3591d50d3085b4c9c Mon Sep 17 00:00:00 2001 From: Shing Rui Date: Wed, 12 Jun 2024 23:11:12 +0800 Subject: [PATCH] Fixed interrupt app can not kill task. --- main.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 31cec36..580b0cf 100644 --- a/main.js +++ b/main.js @@ -6,8 +6,10 @@ console.log('NODE_ENV', NODE_ENV) process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true' +let win + function createWindow() { - const win = new BrowserWindow({ + win = new BrowserWindow({ minWidth: 1024, minHeight: 768, webPreferences: { @@ -61,3 +63,29 @@ app.on('window-all-closed', () => { app.quit() } }) + +const handleTerminationSignals = () => { + if (win) { + win.close() + } + app.quit() +} + +if (process.platform === 'win32') { + require('readline') + .createInterface({ + input: process.stdin, + output: process.stdout + }) + .on('SIGINT', () => { + handleTerminationSignals() + }) +} + +process.on('SIGINT', () => { + handleTerminationSignals() +}) + +process.on('SIGTERM', () => { + handleTerminationSignals() +})