From 0b79e4945243112d43411b1b5a5cf1670346c134 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 17 Mar 2017 07:41:01 -0400 Subject: [PATCH] Add context menu Has Cut, Copy, Paste, and when in developer mode there's also Inspect Element --- app/menu/context-menu.js | 36 ++++++++++++++++++++++++++++++++++++ ui/js/component/drawer.js | 2 +- ui/js/main.js | 9 +++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/menu/context-menu.js diff --git a/app/menu/context-menu.js b/app/menu/context-menu.js new file mode 100644 index 000000000..f38de5d1c --- /dev/null +++ b/app/menu/context-menu.js @@ -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); + }, +}; diff --git a/ui/js/component/drawer.js b/ui/js/component/drawer.js index 2cade6e13..bc8f6d666 100644 --- a/ui/js/component/drawer.js +++ b/ui/js/component/drawer.js @@ -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(); } diff --git a/ui/js/main.js b/ui/js/main.js index eb5863fb1..f00c49a69 100644 --- a/ui/js/main.js +++ b/ui/js/main.js @@ -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; -- 2.45.2