diff --git a/index.js b/index.js index 305195d..db6a737 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const cliTruncate = require('cli-truncate'); const {download} = require('electron-dl'); const isDev = require('electron-is-dev'); -const webContents = win => win.webContents || (win.getWebContentsId && electron.remote.webContents.fromId(win.getWebContentsId())); +const webContents = win => win.webContents; const decorateMenuItem = menuItem => { return (options = {}) => { @@ -292,18 +292,8 @@ const create = (win, options) => { } if (menuTemplate.length > 0) { - const menu = (electron.remote ? electron.remote.Menu : electron.Menu).buildFromTemplate(menuTemplate); - - /* - When `electron.remote` is not available, this runs in the browser process. - - We can safely use `win` in this case as it refers to the window the - context-menu should open in. - - When this is being called from a web view, we can't use `win` as this - would refer to the web view which is not allowed to render a popup menu. - */ - menu.popup(electron.remote ? electron.remote.getCurrentWindow() : win); + const menu = electron.Menu.buildFromTemplate(menuTemplate); + menu.popup(win); } }; @@ -319,6 +309,10 @@ const create = (win, options) => { }; module.exports = (options = {}) => { + if (process.type === 'renderer') { + throw new Error('Cannot use electron-context-menu in renderer process!'); + } + let isDisposed = false; const disposables = []; @@ -379,19 +373,17 @@ module.exports = (options = {}) => { return dispose; } - for (const win of (electron.BrowserWindow || electron.remote.BrowserWindow).getAllWindows()) { + for (const win of electron.BrowserWindow.getAllWindows()) { init(win); } - const app = electron.app || electron.remote.app; - const onWindowCreated = (event, win) => { init(win); }; - app.on('browser-window-created', onWindowCreated); + electron.app.on('browser-window-created', onWindowCreated); disposables.push(() => { - app.removeListener('browser-window-created', onWindowCreated); + electron.app.removeListener('browser-window-created', onWindowCreated); }); return dispose; diff --git a/readme.md b/readme.md index b6154f3..dcf9e01 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ Electron doesn't have a built-in context menu. You're supposed to handle that yourself. But it's both tedious and hard to get right. This module gives you a nice extensible context menu with spellchecking and items like `Cut`/`Copy`/`Paste` for text, `Save Image` for images, and `Copy Link` for links. It also adds an `Inspect Element` menu item when in development to quickly view items in the inspector like in Chrome. -You can use this module directly in both the main and renderer process. +This package can only be used in the main process. ## Install