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) {