From c09a7e8bbc8496c2322a3323228e65bcdd3ffea4 Mon Sep 17 00:00:00 2001 From: Franco Montenegro Date: Wed, 6 Jan 2021 02:31:29 -0300 Subject: [PATCH] Properly restore maximized window from taskbar if required --- electron/createTray.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/electron/createTray.js b/electron/createTray.js index e46012c2c..11fe58e84 100644 --- a/electron/createTray.js +++ b/electron/createTray.js @@ -6,6 +6,26 @@ let tray; export default window => { let iconPath; + /* + * A maximized window can't be properly + * restored when minimized to the taskbar + * (it will be restored/showed as unmaximized). + * + * window.isMaximized() will also return + * false when minimizing a maximized window. + * + * The safest way to keep track of the + * maximized state using maximize and + * unmaximize events. + */ + let isWindowMaximized = false; + window.on('maximize', () => { + isWindowMaximized = true; + }); + window.on('unmaximize', () => { + isWindowMaximized = false; + }); + switch (process.platform) { case 'darwin': { iconPath = 'static/img/tray/mac/trayTemplate.png'; @@ -22,18 +42,21 @@ export default window => { tray = new Tray(process.env.NODE_ENV === 'development' ? iconPath : path.join(process.resourcesPath, iconPath)); - tray.on('double-click', () => { + const restoreFromTray = () => { + if (isWindowMaximized) { + window.maximize(); + } window.show(); - }); + }; + + tray.on('double-click', restoreFromTray); tray.setToolTip('LBRY App'); const template = [ { label: `Open ${app.name}`, - click: () => { - window.show(); - }, + click: restoreFromTray, }, { role: 'quit' }, ];