From 257e3423e91cd013676b287a7723de73c3ec9886 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Tue, 24 Jan 2017 23:23:51 -0200 Subject: [PATCH] Prevent error from tray when window reloads Closes #318 Closes #322 --- src/scripts/menus.js | 8 ++++---- src/scripts/tray.js | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/scripts/menus.js b/src/scripts/menus.js index b763425987df..70d8ac62f788 100644 --- a/src/scripts/menus.js +++ b/src/scripts/menus.js @@ -139,8 +139,8 @@ if (process.platform === 'darwin') { accelerator: 'Command+Shift+R', click: function () { var mainWindow = remote.getCurrentWindow(); - if (mainWindow.tray) { - mainWindow.tray.destroy(); + if (mainWindow.destroyTray) { + mainWindow.destroyTray(); } mainWindow.reload(); } @@ -354,8 +354,8 @@ if (process.platform === 'darwin') { accelerator: 'Ctrl+Shift+R', click: function () { var mainWindow = remote.getCurrentWindow(); - if (mainWindow.tray) { - mainWindow.tray.destroy(); + if (mainWindow.destroyTray) { + mainWindow.destroyTray(); } mainWindow.reload(); } diff --git a/src/scripts/tray.js b/src/scripts/tray.js index de0a507795de..fd99a887a4c4 100644 --- a/src/scripts/tray.js +++ b/src/scripts/tray.js @@ -57,13 +57,16 @@ function createAppTray () { _tray.setContextMenu(contextMenuHide); } - mainWindow.on('show', () => { + const onShow = function () { _tray.setContextMenu(contextMenuHide); - }); + }; - mainWindow.on('hide', () => { + const onHide = function () { _tray.setContextMenu(contextMenuShow); - }); + }; + + mainWindow.on('show', onShow); + mainWindow.on('hide', onHide); _tray.setToolTip(remote.app.getName()); @@ -75,7 +78,11 @@ function createAppTray () { mainWindow.show(); }); - mainWindow.tray = _tray; + mainWindow.destroyTray = function () { + mainWindow.removeListener('show', onShow); + mainWindow.removeListener('hide', onHide); + _tray.destroy(); + }; } function showTrayAlert (showAlert, title) {