Properly restore maximized window from taskbar if required
This commit is contained in:
parent
a65162c204
commit
c09a7e8bbc
1 changed files with 28 additions and 5 deletions
|
@ -6,6 +6,26 @@ let tray;
|
||||||
export default window => {
|
export default window => {
|
||||||
let iconPath;
|
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) {
|
switch (process.platform) {
|
||||||
case 'darwin': {
|
case 'darwin': {
|
||||||
iconPath = 'static/img/tray/mac/trayTemplate.png';
|
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 = 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();
|
window.show();
|
||||||
});
|
};
|
||||||
|
|
||||||
|
tray.on('double-click', restoreFromTray);
|
||||||
|
|
||||||
tray.setToolTip('LBRY App');
|
tray.setToolTip('LBRY App');
|
||||||
|
|
||||||
const template = [
|
const template = [
|
||||||
{
|
{
|
||||||
label: `Open ${app.name}`,
|
label: `Open ${app.name}`,
|
||||||
click: () => {
|
click: restoreFromTray,
|
||||||
window.show();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ role: 'quit' },
|
{ role: 'quit' },
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue