Add browser side support for reading files from renderer.
This commit is contained in:
parent
0f7652dc85
commit
695509e267
1 changed files with 9 additions and 0 deletions
|
@ -5,6 +5,8 @@ const electron = require('electron')
|
||||||
const v8Util = process.atomBinding('v8_util')
|
const v8Util = process.atomBinding('v8_util')
|
||||||
const {ipcMain, isPromise, webContents} = electron
|
const {ipcMain, isPromise, webContents} = electron
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
const objectsRegistry = require('./objects-registry')
|
const objectsRegistry = require('./objects-registry')
|
||||||
|
|
||||||
const hasProp = {}.hasOwnProperty
|
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) {
|
ipcMain.on('ELECTRON_BROWSER_GET_BUILTIN', function (event, module) {
|
||||||
try {
|
try {
|
||||||
event.returnValue = valueToMeta(event.sender, electron[module])
|
event.returnValue = valueToMeta(event.sender, electron[module])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue