2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-15 17:27:08 +00:00
nativefier/app/src/components/contextMenu/contextMenu.js
David Kramer ec1023d7ef Fix #95, #384 - Use electron-context-menu, supporting cut/copy/paste (PR #588)
The electron-context-menu package uses the context-menu event emitted by WebContents (API added in Electron 1.0.2) to add a general context menu supporting generic actions (e.g. cut/copy/paste) that can be customized. This change replaces the existing context menu, which relies on adding an event listener in preload.js, with one built using the new package.
2018-04-22 19:48:56 -04:00

28 lines
639 B
JavaScript

import { shell, BrowserWindow } from 'electron';
import contextMenu from 'electron-context-menu';
function initContextMenu() {
contextMenu({
prepend: (params) => {
const items = [];
if (params.linkURL) {
items.push({
label: 'Open Link in Default Browser',
click: () => {
shell.openExternal(params.linkURL);
},
});
items.push({
label: 'Open Link in New Window',
click: () => {
new BrowserWindow().loadURL(params.linkURL);
},
});
}
return items;
},
});
}
export default initContextMenu;