From dd781c4f632861e809d7b400859a08cf0376b6ce Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Thu, 10 Sep 2020 09:17:17 -0700 Subject: [PATCH] chore: deprecate remote (#25293) --- docs/breaking-changes.md | 19 +++++++++++++++++++ lib/renderer/api/remote.ts | 3 +++ spec-main/events-helpers.ts | 2 +- spec-main/webview-spec.ts | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index 9caffe19b04..27cc43aea65 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -64,6 +64,25 @@ If your crash ingestion server does not support compressed payloads, you can turn off compression by specifying `{ compress: false }` in the crash reporter options. +### Deprecated: `remote` module + +The `remote` module is deprecated in Electron 12, and will be removed in +Electron 14. It is replaced by the +[`@electron/remote`](https://github.com/electron/remote) module. + +```js +// Deprecated in Electron 12: +const { BrowserWindow } = require('electron').remote +``` + +```js +// Replace with: +const { BrowserWindow } = require('@electron/remote') + +// In the main process: +require('@electron/remote/main').initialize() +``` + ### Deprecated: `shell.moveItemToTrash()` The synchronous `shell.moveItemToTrash()` has been replaced by the new, diff --git a/lib/renderer/api/remote.ts b/lib/renderer/api/remote.ts index b30fe3202b0..257e0bec8f0 100644 --- a/lib/renderer/api/remote.ts +++ b/lib/renderer/api/remote.ts @@ -3,9 +3,12 @@ import { isPromise, isSerializableObject, serialize, deserialize } from '../../c import { MetaTypeFromRenderer, ObjectMember, ObjProtoDescriptor, MetaType } from '../../common/remote/types'; import { ipcRendererInternal } from '../ipc-renderer-internal'; import type { BrowserWindow, WebContents } from 'electron/main'; +import deprecate from '@electron/internal/common/api/deprecate'; import { browserModuleNames } from '@electron/internal/browser/api/module-names'; import { commonModuleList } from '@electron/internal/common/api/module-list'; +deprecate.log('The remote module is deprecated. Use https://github.com/electron/remote instead.'); + const v8Util = process._linkedBinding('electron_common_v8_util'); const { hasSwitch } = process._linkedBinding('electron_common_command_line'); diff --git a/spec-main/events-helpers.ts b/spec-main/events-helpers.ts index 3a0c58b5388..4cb3d231db7 100644 --- a/spec-main/events-helpers.ts +++ b/spec-main/events-helpers.ts @@ -42,7 +42,7 @@ export const emittedNTimes = async (emitter: NodeJS.EventEmitter, eventName: str }; export const emittedUntil = async (emitter: NodeJS.EventEmitter, eventName: string, untilFn: Function) => { - const p = new Promise(resolve => { + const p = new Promise(resolve => { const handler = (...args: any[]) => { if (untilFn(...args)) { emitter.removeListener(eventName, handler); diff --git a/spec-main/webview-spec.ts b/spec-main/webview-spec.ts index fe3eba8109f..b2d84fc123e 100644 --- a/spec-main/webview-spec.ts +++ b/spec-main/webview-spec.ts @@ -625,7 +625,7 @@ describe(' tag', function () { sandbox: sandbox.toString() }); const [, webViewContents] = await emittedOnce(app, 'web-contents-created'); - const [, , message] = await emittedOnce(webViewContents, 'console-message'); + const [, , message] = await emittedUntil(webViewContents, 'console-message', (event: any, level: any, message: string) => !/deprecated/.test(message)); const typeOfRemote = JSON.parse(message); expect(typeOfRemote).to.equal('object');