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' }, ];