Commit 0418e87f authored by Luke Schoen's avatar Luke Schoen
Browse files

review-fix: Add Show/Hide Fether and Quit items to a separate tray context menu

parent b09de996
Pipeline #31610 passed with stage
in 1 minute and 48 seconds
......@@ -5,21 +5,21 @@
import electron from 'electron';
import { getContextMenuTemplate } from '../template';
import { getContextTrayMenuTemplate } from '../template';
const { Menu } = electron;
let hasCalledInitMenu = false;
class FetherContextMenu {
class FetherContextTrayMenu {
constructor (fetherApp) {
if (hasCalledInitMenu) {
throw new Error(
'Unable to initialise Fether context menu more than once'
'Unable to initialise Fether context tray menu more than once'
);
}
this.setMenuTemplate(getContextMenuTemplate(fetherApp));
this.setMenuTemplate(getContextTrayMenuTemplate(fetherApp));
this.buildMenuTemplate(this.menuTemplate);
}
......@@ -36,4 +36,4 @@ class FetherContextMenu {
};
}
export default FetherContextMenu;
export default FetherContextTrayMenu;
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import electron from 'electron';
import { getContextWindowMenuTemplate } from '../template';
const { Menu } = electron;
let hasCalledInitMenu = false;
class FetherContextWindowMenu {
constructor (fetherApp) {
if (hasCalledInitMenu) {
throw new Error(
'Unable to initialise Fether context window menu more than once'
);
}
this.setMenuTemplate(getContextWindowMenuTemplate(fetherApp));
this.buildMenuTemplate(this.menuTemplate);
}
setMenuTemplate = menuTemplate => {
this.menuTemplate = menuTemplate;
};
buildMenuTemplate = menuTemplate => {
this.builtMenu = Menu.buildFromTemplate(menuTemplate);
};
getMenu = () => {
return this.builtMenu;
};
}
export default FetherContextWindowMenu;
......@@ -4,6 +4,7 @@
// SPDX-License-Identifier: BSD-3-Clause
import FetherMenubarMenu from './menubar';
import FetherContextMenu from './context';
import FetherContextTrayMenu from './contextTray';
import FetherContextWindowMenu from './contextWindow';
export { FetherMenubarMenu, FetherContextMenu };
export { FetherMenubarMenu, FetherContextTrayMenu, FetherContextWindowMenu };
......@@ -137,11 +137,29 @@ const getMenubarMenuTemplate = fetherApp => {
return template;
};
const getContextMenuTemplate = fetherApp => {
const getContextTrayMenuTemplate = fetherApp => {
if (fetherApp.options.withTaskbar) {
const template = [
{
label: 'Show/Hide Fether',
click () {
fetherApp.win.isVisible()
? fetherApp.win.hide()
: fetherApp.win.show();
}
},
{ label: 'Quit', role: 'quit' }
];
return template;
}
};
const getContextWindowMenuTemplate = fetherApp => {
let template = getMenubarMenuTemplate(fetherApp);
if (fetherApp.options.withTaskbar) {
// Remove File and Help menus in taskbar mode for context menu
// Remove File and Help menus in taskbar mode for window context menu
template.shift();
template.pop();
template.push();
......@@ -163,4 +181,8 @@ const getContextMenuTemplate = fetherApp => {
return template;
};
export { getMenubarMenuTemplate, getContextMenuTemplate };
export {
getContextTrayMenuTemplate,
getContextWindowMenuTemplate,
getMenubarMenuTemplate
};
......@@ -33,7 +33,7 @@ export default async (fetherApp, event, action, ...args) => {
if (!fetherApp.win) {
return;
}
fetherApp.contextMenu.getMenu().popup({ window: fetherApp.win });
fetherApp.contextWindowMenu.getMenu().popup({ window: fetherApp.win });
break;
}
case 'check-clock-sync': {
......
......@@ -22,21 +22,22 @@ function loadTray (fetherApp) {
showTrayBalloon(fetherApp);
}
tray.setContextMenu(fetherApp.contextTrayMenu.getMenu());
// Right-click event listener does not work on Windows
tray.on('right-click', () => {
pino.info('Detected right-click on tray icon');
if (process.platform !== 'darwin') {
onTrayClick(fetherApp);
}
tray.popUpContextMenu();
fetherApp.win.focus();
});
// Single click event listener works on Windows
tray.on('click', () => {
pino.info('Detected single click on tray icon');
fetherApp.win.focus();
onTrayClick(fetherApp);
fetherApp.win.focus();
});
tray.setToolTip(options.tooltip);
tray.setHighlightMode('never');
......
......@@ -3,7 +3,11 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import { FetherContextMenu, FetherMenubarMenu } from '../menu';
import {
FetherContextTrayMenu,
FetherContextWindowMenu,
FetherMenubarMenu
} from '../menu';
import Pino from '../utils/pino';
const pino = Pino();
......@@ -12,7 +16,11 @@ function setupMenu (fetherApp) {
fetherApp.menubarMenu = new FetherMenubarMenu(fetherApp);
fetherApp.menubarMenu.setMenu();
fetherApp.contextMenu = new FetherContextMenu(fetherApp);
if (fetherApp.options.withTaskbar) {
fetherApp.contextTrayMenu = new FetherContextTrayMenu(fetherApp);
}
fetherApp.contextWindowMenu = new FetherContextWindowMenu(fetherApp);
/**
* Toggle the Fether menubar menu in window frame when options `frame: true`.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment