Skip to content

Commit

Permalink
Merge pull request RocketChat#324 from RocketChat/fix/318-reoccurring…
Browse files Browse the repository at this point in the history
…-error-popup

Prevent error from tray when window reloads
  • Loading branch information
engelgabriel authored Jan 26, 2017
2 parents 3a730a5 + 257e342 commit f21644d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/scripts/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
17 changes: 12 additions & 5 deletions src/scripts/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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) {
Expand Down

0 comments on commit f21644d

Please sign in to comment.