Skip to content

Commit

Permalink
Merge pull request #148 from electron-userland/no-remote-docs
Browse files Browse the repository at this point in the history
Show how to avoid using `electron.remote` on renderer processes
  • Loading branch information
jviotti authored Oct 5, 2020
2 parents 682d278 + 716270b commit 08ec5ec
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ $ npm install --save electron-json-storage

You can require this module from either the **main** or **renderer** process (with and without `remote`).

Running on Electron >10 renderer processes
------------------------------------------

When loaded in renderer processes, this module will make use of
`electron.remote` in order to fetch the `userData` path.

Electron 10 now [defaults `enableRemoteModule` to
false](https://www.electronjs.org/docs/breaking-changes#default-changed-enableremotemodule-defaults-to-false),
which means that `electron-json-storage` will not work on Electron 10 renderer
processes unless you manually set `enableRemoteModule` to `true`:

```js
const win = new BrowserWindow({
webPreferences: {
enableRemoteModule: true
}
})
```

Alternatively, you can avoid using the `remote` module by:

- Passing the `electron.app.getPath('userData')` value from the **main**
process to your **renderer** processes through IPC or a medium of your choice

- Calling `storage.setDataPath()`, on the **renderer** process, with the user
data path obtained on the previous step before calling any other
`electron-json-storage` function.

If you do this, the user data path will be cached by the renderer process,
which will not need to go through the `remote` module to obtain it.

Documentation
-------------

Expand Down
31 changes: 31 additions & 0 deletions doc/README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ $ npm install --save electron-json-storage
You can require this module from either the **main** or **renderer** process (with and without `remote`).
Running on Electron >10 renderer processes
------------------------------------------
When loaded in renderer processes, this module will make use of
`electron.remote` in order to fetch the `userData` path.
Electron 10 now [defaults `enableRemoteModule` to
false](https://www.electronjs.org/docs/breaking-changes#default-changed-enableremotemodule-defaults-to-false),
which means that `electron-json-storage` will not work on Electron 10 renderer
processes unless you manually set `enableRemoteModule` to `true`:
```js
const win = new BrowserWindow({
webPreferences: {
enableRemoteModule: true
}
})
```
Alternatively, you can avoid using the `remote` module by:
- Passing the `electron.app.getPath('userData')` value from the **main**
process to your **renderer** processes through IPC or a medium of your choice
- Calling `storage.setDataPath()`, on the **renderer** process, with the user
data path obtained on the previous step before calling any other
`electron-json-storage` function.
If you do this, the user data path will be cached by the renderer process,
which will not need to go through the `remote` module to obtain it.
Documentation
-------------
Expand Down

0 comments on commit 08ec5ec

Please sign in to comment.