feat: deprecate ipcRenderer.sendTo() (#39091)

* feat: deprecate ipcRenderer.sendTo()

* docs: add _Deprecated_ to ipcRenderer.sendTo()
This commit is contained in:
Milan Burda 2023-07-21 11:16:44 +02:00 committed by GitHub
parent 3a5e2dd90c
commit ada8eb33b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 2 deletions

View file

@ -192,7 +192,7 @@ ipcMain.on('port', (e, msg) => {
For more information on using `MessagePort` and `MessageChannel`, see the [MDN For more information on using `MessagePort` and `MessageChannel`, see the [MDN
documentation](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel). documentation](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel).
### `ipcRenderer.sendTo(webContentsId, channel, ...args)` ### `ipcRenderer.sendTo(webContentsId, channel, ...args)` _Deprecated_
* `webContentsId` number * `webContentsId` number
* `channel` string * `channel` string

View file

@ -4,5 +4,5 @@
* `senderId` Integer - The `webContents.id` that sent the message, you can call `event.sender.sendTo(event.senderId, ...)` to reply to the message, see [ipcRenderer.sendTo][ipc-renderer-sendto] for more information. This only applies to messages sent from a different renderer. Messages sent directly from the main process set `event.senderId` to `0`. * `senderId` Integer - The `webContents.id` that sent the message, you can call `event.sender.sendTo(event.senderId, ...)` to reply to the message, see [ipcRenderer.sendTo][ipc-renderer-sendto] for more information. This only applies to messages sent from a different renderer. Messages sent directly from the main process set `event.senderId` to `0`.
* `ports` [MessagePort][][] - A list of MessagePorts that were transferred with this message * `ports` [MessagePort][][] - A list of MessagePorts that were transferred with this message
[ipc-renderer-sendto]: ../ipc-renderer.md#ipcrenderersendtowebcontentsid-channel-args [ipc-renderer-sendto]: ../ipc-renderer.md#ipcrenderersendtowebcontentsid-channel-args-deprecated
[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort [MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort

View file

@ -21,6 +21,10 @@ macOS 10.13 (High Sierra) and macOS 10.14 (Mojave) are no longer supported by [C
Older versions of Electron will continue to run on these operating systems, but macOS 10.15 (Catalina) Older versions of Electron will continue to run on these operating systems, but macOS 10.15 (Catalina)
or later will be required to run Electron v27.0.0 and higher. or later will be required to run Electron v27.0.0 and higher.
### Deprecated: `ipcRenderer.sendTo()`
The `ipcRenderer.sendTo()` API has been deprecated. It should be replaced by setting up a [`MessageChannel`](tutorial/message-ports.md#setting-up-a-messagechannel-between-two-renderers) between the renderers.
## Planned Breaking API Changes (25.0) ## Planned Breaking API Changes (25.0)
### Deprecated: `protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol` ### Deprecated: `protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol`

View file

@ -143,6 +143,7 @@ auto_filenames = {
sandbox_bundle_deps = [ sandbox_bundle_deps = [
"lib/common/api/native-image.ts", "lib/common/api/native-image.ts",
"lib/common/define-properties.ts", "lib/common/define-properties.ts",
"lib/common/deprecate.ts",
"lib/common/ipc-messages.ts", "lib/common/ipc-messages.ts",
"lib/common/web-view-methods.ts", "lib/common/web-view-methods.ts",
"lib/common/webpack-globals-provider.ts", "lib/common/webpack-globals-provider.ts",
@ -268,6 +269,7 @@ auto_filenames = {
"lib/common/api/native-image.ts", "lib/common/api/native-image.ts",
"lib/common/api/shell.ts", "lib/common/api/shell.ts",
"lib/common/define-properties.ts", "lib/common/define-properties.ts",
"lib/common/deprecate.ts",
"lib/common/init.ts", "lib/common/init.ts",
"lib/common/ipc-messages.ts", "lib/common/ipc-messages.ts",
"lib/common/reset-search-paths.ts", "lib/common/reset-search-paths.ts",
@ -306,6 +308,7 @@ auto_filenames = {
"lib/common/api/native-image.ts", "lib/common/api/native-image.ts",
"lib/common/api/shell.ts", "lib/common/api/shell.ts",
"lib/common/define-properties.ts", "lib/common/define-properties.ts",
"lib/common/deprecate.ts",
"lib/common/init.ts", "lib/common/init.ts",
"lib/common/ipc-messages.ts", "lib/common/ipc-messages.ts",
"lib/common/reset-search-paths.ts", "lib/common/reset-search-paths.ts",

View file

@ -1,4 +1,5 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import * as deprecate from '@electron/internal/common/deprecate';
const { ipc } = process._linkedBinding('electron_renderer_ipc'); const { ipc } = process._linkedBinding('electron_renderer_ipc');
@ -18,6 +19,7 @@ ipcRenderer.sendToHost = function (channel, ...args) {
}; };
ipcRenderer.sendTo = function (webContentsId, channel, ...args) { ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
deprecate.warnOnce('ipcRenderer.sendTo');
return ipc.sendTo(webContentsId, channel, args); return ipc.sendTo(webContentsId, channel, args);
}; };