mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
docs: add missing ipcRenderer.off() / ipcRenderer.addListener() aliases (#39816)
* docs: add missing `ipcRenderer.off()` / `ipcRenderer.addListener()` aliases * Update docs/api/ipc-renderer.md Co-authored-by: David Sanders <dsanders11@ucsbalum.com> * fix ipcRenderer.removeListener * update ts-smoke --------- Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
@@ -562,6 +562,11 @@ globalShortcut.unregisterAll();
|
||||
// ipcMain
|
||||
// https://github.com/electron/electron/blob/main/docs/api/ipc-main.md
|
||||
|
||||
ipcMain.handle('ping-pong', (event, arg: any) => {
|
||||
console.log(arg); // prints "ping"
|
||||
return 'pong';
|
||||
});
|
||||
|
||||
ipcMain.on('asynchronous-message', (event, arg: any) => {
|
||||
console.log(arg); // prints "ping"
|
||||
event.sender.send('asynchronous-reply', 'pong');
|
||||
@@ -572,11 +577,6 @@ ipcMain.on('synchronous-message', (event, arg: any) => {
|
||||
event.returnValue = 'pong';
|
||||
});
|
||||
|
||||
ipcMain.on('synchronous-message', (event, arg: any) => {
|
||||
console.log(arg); // prints "ping"
|
||||
event.returnValue = 'pong';
|
||||
});
|
||||
|
||||
const winWindows = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
|
||||
@@ -4,8 +4,20 @@ import { clipboard, crashReporter, shell } from 'electron/common';
|
||||
|
||||
// In renderer process (web page).
|
||||
// https://github.com/electron/electron/blob/main/docs/api/ipc-renderer.md
|
||||
|
||||
(async () => {
|
||||
console.log(await ipcRenderer.invoke('ping-pong')); // prints "pong"
|
||||
})();
|
||||
|
||||
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
|
||||
|
||||
ipcRenderer.on('test', () => {});
|
||||
ipcRenderer.off('test', () => {});
|
||||
ipcRenderer.once('test', () => {});
|
||||
ipcRenderer.addListener('test', () => {});
|
||||
ipcRenderer.removeListener('test', () => {});
|
||||
ipcRenderer.removeAllListeners('test');
|
||||
|
||||
ipcRenderer.on('asynchronous-reply', (event, arg: any) => {
|
||||
console.log(arg); // prints "pong"
|
||||
event.sender.send('another-message', 'Hello World!');
|
||||
|
||||
Reference in New Issue
Block a user