From c98f3cd040df4e69f31c75e655db6ad625da68f3 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 10 Apr 2016 18:50:00 -0700 Subject: [PATCH] Fix JS error on app quit (#377) This was a rare race condition during app shutdown where a 'wt-' message would be sent from the hidden webtorrent window to the main window after the main window was already closed. Fixes #373 --- main/ipc.js | 2 +- main/windows.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main/ipc.js b/main/ipc.js index 802a4673..b056a248 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -87,7 +87,7 @@ function init () { var oldEmit = ipcMain.emit ipcMain.emit = function (name, e, ...args) { // Relay messages between the main window and the WebTorrent hidden window - if (name.startsWith('wt-')) { + if (name.startsWith('wt-') && !app.isQuitting) { if (e.sender.browserWindowOptions.title === 'webtorrent-hidden-window') { // Send message to main window windows.main.send(name, ...args) diff --git a/main/windows.js b/main/windows.js index 1666e073..670d7273 100644 --- a/main/windows.js +++ b/main/windows.js @@ -72,6 +72,10 @@ function createWebTorrentHiddenWindow () { win.hide() } }) + + win.once('closed', function () { + windows.webtorrent = null + }) } function createMainWindow () {