Skip to content

Commit da81d52

Browse files
authored
Merge pull request #53 from HB9HIL/clean_shutdown
we should free the ports on shutdown
2 parents 87bf771 + 7066735 commit da81d52

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

main.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let powerSaveBlockerId;
99
let tray;
1010
let s_mainWindow;
1111
let msgbacklog=[];
12+
let httpServer;
1213
var WServer;
1314

1415
const DemoAdif='<call:5>DJ7NT <gridsquare:4>JO30 <mode:3>FT8 <rst_sent:3>-15 <rst_rcvd:2>33 <qso_date:8>20240110 <time_on:6>051855 <qso_date_off:8>20240110 <time_off:6>051855 <band:3>40m <freq:8>7.155783 <station_callsign:5>TE1ST <my_gridsquare:6>JO30OO <eor>';
@@ -175,9 +176,23 @@ ipcMain.on("test", async (event,arg) => {
175176
});
176177

177178
app.on('before-quit', () => {
178-
if (tray) {
179-
tray.destroy();
180-
}
179+
console.log('Shutting down servers...');
180+
if (WServer) {
181+
WServer.close();
182+
}
183+
if (httpServer) {
184+
httpServer.close();
185+
}
186+
if (tray) {
187+
tray.destroy();
188+
}
189+
});
190+
191+
process.on('SIGINT', () => {
192+
console.log('SIGINT received, closing servers...');
193+
if (WServer) WServer.close();
194+
if (httpServer) httpServer.close();
195+
process.exit(0);
181196
});
182197

183198
app.on('will-quit', () => {
@@ -424,7 +439,7 @@ function tomsg(msg) {
424439
function startserver() {
425440
try {
426441
tomsg('Waiting for QSO / Listening on UDP 2333');
427-
http.createServer(function (req, res) {
442+
httpServer = http.createServer(function (req, res) {
428443
res.setHeader('Access-Control-Allow-Origin', '*');
429444
res.writeHead(200, {'Content-Type': 'text/plain'});
430445
res.end('');

0 commit comments

Comments
 (0)