From ad78ca03d8a7fc30cc884d7e09b31d7652e379ef Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Mon, 14 Jan 2019 11:23:46 +0100 Subject: [PATCH] Close connections when window closed Fixes #8 --- backend/src/index.ts | 5 +++++ electron.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/backend/src/index.ts b/backend/src/index.ts index 9e78efb..e37aadd 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -57,6 +57,11 @@ export class ConnectionManager { connection.disconnect() delete this.connections[hash] } + + public closeAllConnections() { + Object.keys(this.connections) + .forEach(hash => this.removeConnection(hash)) + } } class UpdateNotifier { diff --git a/electron.js b/electron.js index c2556ae..e298cbb 100644 --- a/electron.js +++ b/electron.js @@ -30,6 +30,11 @@ function createWindow () { // Open the DevTools. // mainWindow.webContents.openDevTools() + // Emitted when the window is closed. + mainWindow.on('close', function () { + connectionManager.closeAllConnections() + }) + // Emitted when the window is closed. mainWindow.on('closed', function () { // Dereference the window object, usually you would store windows