Skip to content

Commit

Permalink
feat(context): add context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Feb 8, 2020
1 parent 2927241 commit 9d6c39e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/renderer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ import App from './App.vue';
import router from './router';
import store from './store';

import './utils/contextMenu';

Vue.config.productionTip = false;

/*
Small plugin to support auto resizing before create a Vue
You can use it like this in your components:
{
electron: {
width: 100,
height: 100
}
}
*/
const Electron = {
install(Vue) {
Vue.mixin({
Expand Down
47 changes: 47 additions & 0 deletions src/renderer/src/utils/contextMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { remote } = window.require('electron');
const { Menu, MenuItem } = remote;

const menu = new Menu();
let mousePosition = {
x: 0,
y: 0
};

// Add dec context menu
if (process.env.NODE_ENV === 'development') {
menu.append(
new MenuItem({
label: 'Inspect Element',
click: e =>
remote
.getCurrentWindow()
.inspectElement(mousePosition.x, mousePosition.y)
})
);
menu.append(new MenuItem({ type: 'separator' }));
}

// Menu items -> https://electronjs.org/docs/api/menu-item
menu.append(
new MenuItem({
label: 'MenuItem2',
type: 'normal'
})
);

window.addEventListener(
'contextmenu',
e => {
e.preventDefault();

mousePosition = {
x: e.x,
y: e.y
};

menu.popup({
window: remote.getCurrentWindow()
});
},
false
);

0 comments on commit 9d6c39e

Please sign in to comment.