Commit 81ab2bfaf7653df34639deb578b81f7e80308bb0
add right click context menu
Matt McKegg committed on 8/14/2017, 4:45:25 AMParent: 49bee78f3c1fec7174a11ee2c7277f5c9a7f47fc
Files changed
main.js | changed |
context-menu.js | added |
main.js | ||
---|---|---|
@@ -4,8 +4,11 @@ | ||
4 | 4 | |
5 | 5 | // polyfills |
6 | 6 | require('setimmediate') |
7 | 7 | |
8 | +// add inspect right click menu | |
9 | +require('./context-menu') | |
10 | + | |
8 | 11 | // from more specialized to more general |
9 | 12 | const sockets = combine( |
10 | 13 | require('./'), |
11 | 14 | require('patch-history'), |
context-menu.js | ||
---|---|---|
@@ -1,0 +1,24 @@ | ||
1 | +const electron = require('electron') | |
2 | +const remote = electron.remote | |
3 | +const Menu = remote.Menu | |
4 | + | |
5 | +var rightClickPosition = null | |
6 | + | |
7 | +const menu = Menu.buildFromTemplate([ | |
8 | + { label: 'Inspect Element', | |
9 | + click: () => { | |
10 | + remote.getCurrentWindow().inspectElement(rightClickPosition.x, rightClickPosition.y) | |
11 | + } | |
12 | + }, | |
13 | + { label: 'Inspect Background Process', | |
14 | + click: () => { | |
15 | + electron.ipcRenderer.send('open-background-devtools') | |
16 | + } | |
17 | + } | |
18 | +]) | |
19 | + | |
20 | +window.addEventListener('contextmenu', (e) => { | |
21 | + e.preventDefault() | |
22 | + rightClickPosition = {x: e.x, y: e.y} | |
23 | + menu.popup(remote.getCurrentWindow(), {async: true}) | |
24 | +}, false) |
Built with git-ssb-web