Skip to content

Commit

Permalink
Change tray icon click to always show/focus window (#2984)
Browse files Browse the repository at this point in the history
* Added function to always show the window on tray icon click and reassigned click event

* Refactored the code to force the window on top into its own function
  • Loading branch information
Herohtar authored and scottnonnenberg-signal committed Jan 2, 2019
1 parent a21d63e commit 22ca4f9
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions app/tray_icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ function createTrayIcon(getMainWindow, messages) {

tray = new Tray(iconNoNewMessages);

tray.forceOnTop = mainWindow => {
if (mainWindow) {
// On some versions of GNOME the window may not be on top when restored.
// This trick should fix it.
// Thanks to: https://github.com/Enrico204/Whatsapp-Desktop/commit/6b0dc86b64e481b455f8fce9b4d797e86d000dc1
mainWindow.setAlwaysOnTop(true);
mainWindow.focus();
mainWindow.setAlwaysOnTop(false);
}
}

tray.toggleWindowVisibility = () => {
const mainWindow = getMainWindow();
if (mainWindow) {
Expand All @@ -25,13 +36,20 @@ function createTrayIcon(getMainWindow, messages) {
} else {
mainWindow.show();

// On some versions of GNOME the window may not be on top when restored.
// This trick should fix it.
// Thanks to: https://github.com/Enrico204/Whatsapp-Desktop/commit/6b0dc86b64e481b455f8fce9b4d797e86d000dc1
mainWindow.setAlwaysOnTop(true);
mainWindow.focus();
mainWindow.setAlwaysOnTop(false);
tray.forceOnTop(mainWindow);
}
}
tray.updateContextMenu();
};

tray.showWindow = () => {
const mainWindow = getMainWindow();
if (mainWindow) {
if (!mainWindow.isVisible()) {
mainWindow.show();
}

tray.forceOnTop(mainWindow);
}
tray.updateContextMenu();
};
Expand Down Expand Up @@ -70,7 +88,7 @@ function createTrayIcon(getMainWindow, messages) {
}
};

tray.on('click', tray.toggleWindowVisibility);
tray.on('click', tray.showWindow);

tray.setToolTip(messages.trayTooltip.message);
tray.updateContextMenu();
Expand Down

0 comments on commit 22ca4f9

Please sign in to comment.