diff --git a/main.js b/main.js index d4988b3..26813a7 100644 --- a/main.js +++ b/main.js @@ -9,6 +9,7 @@ let powerSaveBlockerId; let tray; let s_mainWindow; let msgbacklog=[]; +let httpServer; var WServer; const DemoAdif='DJ7NT JO30 FT8 -15 33 20240110 051855 20240110 051855 40m 7.155783 TE1ST JO30OO '; @@ -175,9 +176,23 @@ ipcMain.on("test", async (event,arg) => { }); app.on('before-quit', () => { - if (tray) { - tray.destroy(); - } + console.log('Shutting down servers...'); + if (WServer) { + WServer.close(); + } + if (httpServer) { + httpServer.close(); + } + if (tray) { + tray.destroy(); + } +}); + +process.on('SIGINT', () => { + console.log('SIGINT received, closing servers...'); + if (WServer) WServer.close(); + if (httpServer) httpServer.close(); + process.exit(0); }); app.on('will-quit', () => { @@ -424,7 +439,7 @@ function tomsg(msg) { function startserver() { try { tomsg('Waiting for QSO / Listening on UDP 2333'); - http.createServer(function (req, res) { + httpServer = http.createServer(function (req, res) { res.setHeader('Access-Control-Allow-Origin', '*'); res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('');