Properly restore maximized window from taskbar if required

This commit is contained in:
Franco Montenegro 2021-01-06 02:31:29 -03:00 committed by Sean Yesmunt
parent a65162c204
commit c09a7e8bbc

View file

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