Add browser side support for reading files from renderer.

This commit is contained in:
Thiago de Arruda 2016-08-21 07:22:52 -03:00
parent 0f7652dc85
commit 695509e267

View file

@ -5,6 +5,8 @@ const electron = require('electron')
const v8Util = process.atomBinding('v8_util')
const {ipcMain, isPromise, webContents} = electron
const fs = require('fs')
const objectsRegistry = require('./objects-registry')
const hasProp = {}.hasOwnProperty
@ -235,6 +237,13 @@ ipcMain.on('ELECTRON_BROWSER_REQUIRE', function (event, module) {
}
})
ipcMain.on('ELECTRON_BROWSER_READ_FILE', function (event, file) {
fs.readFile(file, (err, data) => {
if (err) event.returnValue = {err: err.message}
else event.returnValue = {data: data.toString()}
})
})
ipcMain.on('ELECTRON_BROWSER_GET_BUILTIN', function (event, module) {
try {
event.returnValue = valueToMeta(event.sender, electron[module])