From 695509e267b45992f6bc287bcf0851e48462cd38 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sun, 21 Aug 2016 07:22:52 -0300 Subject: [PATCH] Add browser side support for reading files from renderer. --- lib/browser/rpc-server.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index 31e5a37732c..447b12e3b28 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -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])