mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-15 17:27:08 +00:00
ec1023d7ef
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.
28 lines
639 B
JavaScript
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;
|