docs: remove references to 'remote' from app-arch tutorial (#24815)

This commit is contained in:
Jeremy Rose 2020-08-04 12:08:35 -07:00 committed by GitHub
parent 01a2e23194
commit 9c234f3f3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,11 +38,11 @@ process of the web page must communicate with the main process to request that
the main process perform those operations. the main process perform those operations.
> #### Aside: Communication Between Processes > #### Aside: Communication Between Processes
> In Electron, we have several ways to communicate between the main process > In Electron, communicating between the main process and renderer processes,
and renderer processes, such as [`ipcRenderer`](../api/ipc-renderer.md) and > is done through the [`ipcRenderer`](../api/ipc-renderer.md) and
[`ipcMain`](../api/ipc-main.md) modules for sending messages, and the > [`ipcMain`](../api/ipc-main.md) modules. There is also an FAQ entry on [how
[remote](../api/remote.md) module for RPC style communication. There is also > to share data between web pages][share-data].
an FAQ entry on [how to share data between web pages][share-data].
## Using Electron APIs ## Using Electron APIs
@ -71,20 +71,26 @@ const win = new BrowserWindow()
``` ```
Since communication between the processes is possible, a renderer process Since communication between the processes is possible, a renderer process
can call upon the main process to perform tasks. Electron comes with a can call upon the main process to perform tasks through IPC.
module called `remote` that exposes APIs usually only available on the
main process. In order to create a `BrowserWindow` from a renderer process,
we'd use the remote as a middle-man:
```javascript ```javascript
// This will work in a renderer process, but be `undefined` in the // In the main process:
// main process: const { ipcMain } = require('electron')
const { remote } = require('electron')
const { BrowserWindow } = remote
const win = new BrowserWindow() ipcMain.handle('perform-action', (event, ...args) => {
// ... do something on behalf of the renderer ...
})
// In the renderer process:
const { ipcRenderer } = require('electron')
ipcRenderer.invoke('perform-action', ...args)
``` ```
Note that code in the renderer may not be trustworthy, so it's important
to carefully validate in the main process requests that come from renderers,
especially if they host third-party content.
## Using Node.js APIs ## Using Node.js APIs
Electron exposes full access to Node.js both in the main and the renderer Electron exposes full access to Node.js both in the main and the renderer