Add context menu #17

Merged
alexliebowitz merged 1 commit from context-menu into master 2017-03-17 17:38:37 +01:00
3 changed files with 46 additions and 1 deletions

36
app/menu/context-menu.js Normal file
View file

@ -0,0 +1,36 @@
const {Menu} = require('electron');
const electron = require('electron');
const app = electron.app;
const contextMenuTemplate = [
{
role: 'cut',
},
{
role: 'copy',
},
{
role: 'paste',
},
];
module.exports = {
showContextMenu(win, posX, posY, showDevItems) {
let template = contextMenuTemplate.slice();
if (showDevItems) {
template.push({
type: 'separator',
});
template.push(
{
label: 'Inspect Element',
click() {
win.inspectElement(posX, posY);
}
}
);
}
Menu.buildFromTemplate(template).popup(win);
},
};

View file

@ -21,7 +21,7 @@ var drawerImageStyle = { //@TODO: remove this, img should be properly scaled onc
var Drawer = React.createClass({
handleLogoClicked: function(event) {
if (event.ctrlKey && event.shiftKey) {
if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
window.location.href = 'index.html?developer'
event.preventDefault();
}

View file

@ -5,8 +5,17 @@ import lighthouse from './lighthouse.js';
import App from './app.js';
import SplashScreen from './component/splash.js';
const {remote} = require('electron');
const contextMenu = remote.require('./menu/context-menu');
lbry.showMenuIfNeeded();
window.addEventListener('contextmenu', (event) => {
contextMenu.showContextMenu(remote.getCurrentWindow(), event.x, event.y,
lbry.getClientSetting('showDeveloperMenu'));
event.preventDefault();
});
var init = function() {
window.lbry = lbry;
window.lighthouse = lighthouse;