refactor: use helpers when using the remote module in sandboxed renderers (#15960)

This commit is contained in:
Milan Burda 2018-12-05 19:07:32 +01:00 committed by Shelley Vohr
parent d243a45173
commit ab2a061b59
11 changed files with 46 additions and 28 deletions

View file

@ -1,5 +1,7 @@
'use strict'
const { getRemote, nativeRequire } = require('@electron/internal/renderer/remote')
window.onload = function () {
// Use menu API to show context menu.
window.InspectorFrontendHost.showContextMenuAtPoint = createMenu
@ -18,7 +20,7 @@ function completeURL (project, path) {
}
window.confirm = function (message, title) {
const { dialog } = require('electron').remote
const dialog = getRemote('dialog')
if (title == null) {
title = ''
}
@ -62,8 +64,7 @@ const convertToMenuTemplate = function (items) {
}
const createMenu = function (x, y, items) {
const { remote } = require('electron')
const { Menu } = remote
const Menu = getRemote('Menu')
let template = convertToMenuTemplate(items)
if (useEditMenuItems(x, y, template)) {
@ -73,7 +74,8 @@ const createMenu = function (x, y, items) {
// The menu is expected to show asynchronously.
setTimeout(function () {
menu.popup({ window: remote.getCurrentWindow() })
const getCurrentWindow = getRemote('getCurrentWindow')
menu.popup({ window: getCurrentWindow() })
})
}
@ -116,7 +118,7 @@ const getEditMenuItems = function () {
}
const showFileChooserDialog = function (callback) {
const { dialog } = require('electron').remote
const dialog = getRemote('dialog')
const files = dialog.showOpenDialog({})
if (files != null) {
callback(pathToHtml5FileObject(files[0]))
@ -124,7 +126,7 @@ const showFileChooserDialog = function (callback) {
}
const pathToHtml5FileObject = function (path) {
const fs = require('fs')
const fs = nativeRequire('fs')
const blob = new Blob([fs.readFileSync(path)])
blob.name = path
return blob