From dfb1dd3c8c3e106fe19fe2801b1b92d662ce8026 Mon Sep 17 00:00:00 2001 From: Amine Mouafik Date: Fri, 21 Feb 2020 17:12:40 +0100 Subject: Make tray bring-to-top/show/hide on click, show menu on right click --- src/lib/Tray.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/lib/Tray.js') diff --git a/src/lib/Tray.js b/src/lib/Tray.js index c0d936599..84ee8e3bb 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js @@ -1,5 +1,5 @@ import { - app, Tray, Menu, systemPreferences, nativeTheme, nativeImage, + app, Menu, nativeImage, nativeTheme, systemPreferences, Tray, } from 'electron'; import path from 'path'; @@ -37,14 +37,20 @@ export default class TrayIcon { ]; const trayMenu = Menu.buildFromTemplate(trayMenuTemplate); - this.trayIcon.setContextMenu(trayMenu); this.trayIcon.on('click', () => { if (app.mainWindow.isMinimized()) { app.mainWindow.restore(); + } else if (app.mainWindow.isVisible()) { + app.mainWindow.hide(); + } else { + app.mainWindow.show(); + app.mainWindow.focus(); } - app.mainWindow.show(); - app.mainWindow.focus(); + }); + + this.trayIcon.on('right-click', () => { + this.trayIcon.popUpContextMenu(trayMenu); }); if (process.platform === 'darwin') { -- cgit v1.2.3-54-g00ecf