Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between IPC send / on and invoke / handle in electron?

https://www.electronjs.org/docs/api/ipc-renderer https://www.electronjs.org/docs/api/ipc-main

I see an article that invoke / handle is asynchronous, but it's possible to use the old send / on. It is easy to return the return value. You do not need to specify webcontents when sending from Main to renderer. The benefits are understandable

https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 I don't think the remote module written in this article is relevant to send / on

like image 854
Fushihara Avatar asked Jan 24 '20 02:01

Fushihara


People also ask

How does IPC work in electron?

The ipcMain module is used to communicate asynchronously from the main process to renderer processes. When used in the main process, the module handles asynchronous and synchronous messages sent from a renderer process (web page). The messages sent from a renderer will be emitted to this module.

How do you send data from main process to renderer process?

To send a message back to the renderer you would use: win. webContents. send('asynchronous-message', {'SAVED': 'File Saved'});


1 Answers

invoke is new api to help ergonomics around existing send / on pair when try to invoke some fn to return values to the sender. You can achieve same thing via send if you prefer to use it, there's no functional differences.

like image 97
OJ Kwon Avatar answered Oct 07 '22 18:10

OJ Kwon