Skip to content

Commit 660a44c

Browse files
author
kirjavascript
committed
upgrade electron v13 -> v26
1 parent 658bc57 commit 660a44c

File tree

13 files changed

+2924
-635
lines changed

13 files changed

+2924
-635
lines changed

package-lock.json

Lines changed: 2479 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"node-sass": "git+https://github.com/TomiBelan/node-sass-wasm#built/master"
1010
},
1111
"dependencies": {
12-
"@electron/remote": "^1.1.0",
12+
"@electron/remote": "^2.0.11",
1313
"@react-spring/web": "^9.6.0",
1414
"arcsecond": "^3.1.2",
1515
"array-move": "^3.0.1",
@@ -18,7 +18,7 @@
1818
"d3-dispatch": "^1.0.3",
1919
"d3-drag": "^1.2.5",
2020
"d3-selection": "^1.1.0",
21-
"electron": "13.6.9",
21+
"electron": "^26.2.4",
2222
"flexlayout-react": "^0.4.5",
2323
"lodash": "^4.17.19",
2424
"marked": "^0.3.6",

static/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function createWindow() {
1919
},
2020
});
2121

22+
require('./remote/main').enable(mainWindow.webContents);
23+
2224
mainWindow.setMenu(null);
2325
mainWindow.loadFile('./index.html');
2426

static/remote/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# @electron/remote
22

3+
[![CircleCI build status](https://circleci.com/gh/electron/remote/tree/main.svg?style=shield)](https://circleci.com/gh/electron/remote/tree/main)
4+
[![npm version](http://img.shields.io/npm/v/@electron/remote.svg)](https://npmjs.org/package/@electron/remote)
5+
36
`@electron/remote` is an [Electron](https://electronjs.org) module that bridges
47
JavaScript objects from the main process to the renderer process. This lets you
58
access main-process-only objects as if they were available in the renderer
69
process.
710

811
> ⚠️ **Warning!** This module has [many subtle
912
> pitfalls][remote-considered-harmful]. There is almost always a better way to
10-
> accomplish your task than using this module. For example, [`ipcRenderer.invoke`](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererinvokechannel-args) can serve many common use cases.
13+
> accomplish your task than using this module. For example, [`ipcRenderer.invoke`](https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrendererinvokechannel-args) can serve many common use cases.
1114
1215
`@electron/remote` is a replacement for the built-in `remote` module in
1316
Electron, which is deprecated and will eventually be removed.
@@ -52,12 +55,13 @@ configure your bundler appropriately to package the code of `@electron/remote`
5255
in the preload script. Of course, [using `@electron/remote` makes the sandbox
5356
much less effective][remote-considered-harmful].
5457

55-
**Note:** `@electron/remote` respects the `enableRemoteModule` WebPreferences
58+
**Note:** In `electron >= 14.0.0`, you must use the new `enable` API to enable the remote module for each desired `WebContents` separately: `require("@electron/remote/main").enable(webContents)`.
59+
60+
In `electron < 14.0.0`, `@electron/remote` respects the `enableRemoteModule` WebPreferences
5661
value. You must pass `{ webPreferences: { enableRemoteModule: true } }` to
5762
the constructor of `BrowserWindow`s that should be granted permission to use
5863
`@electron/remote`.
5964

60-
6165
# API Reference
6266

6367
The `remote` module provides a simple way to do inter-process communication
@@ -85,9 +89,11 @@ of the remote module:
8589
require('@electron/remote/main').initialize()
8690
```
8791

88-
**Note:** The remote module can be disabled for security reasons in the following contexts:
89-
- [`BrowserWindow`](browser-window.md) - by setting the `enableRemoteModule` option to `false`.
90-
- [`<webview>`](webview-tag.md) - by setting the `enableremotemodule` attribute to `false`.
92+
**Note:** In `electron >= 14.0.0` the remote module is disabled by default for any `WebContents` instance and is only enabled for specified `WebContents` after explicitly calling `require("@electron/remote/main").enable(webContents)`.
93+
94+
In `electron < 14.0.0` the remote module can be disabled for security reasons in the following contexts:
95+
- [`BrowserWindow`](https://www.electronjs.org/docs/latest/api/browser-window) - by setting the `enableRemoteModule` option to `false`.
96+
- [`<webview>`](https://www.electronjs.org/docs/latest/api/webview-tag) - by setting the `enableremotemodule` attribute to `false`.
9197

9298
## Remote Objects
9399

@@ -214,8 +220,8 @@ e.g.
214220
```sh
215221
project/
216222
├── main
217-
   ├── foo.js
218-
   └── index.js
223+
├── foo.js
224+
└── index.js
219225
├── package.json
220226
└── renderer
221227
└── index.js

static/remote/dist/src/common/module-names.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@ exports.browserModuleNames = [
2929
'powerMonitor',
3030
'powerSaveBlocker',
3131
'protocol',
32+
'pushNotifications',
33+
'safeStorage',
3234
'screen',
3335
'session',
3436
'ShareMenu',
3537
'systemPreferences',
3638
'TopLevelWindow',
3739
'TouchBar',
3840
'Tray',
41+
'utilityProcess',
3942
'View',
4043
'webContents',
4144
'WebContentsView',
4245
'webFrameMain',
4346
].concat(exports.commonModuleNames);
4447
const features = get_electron_binding_1.getElectronBinding('features');
45-
if (!features || features.isDesktopCapturerEnabled()) {
48+
if (!features || !features.isDesktopCapturerEnabled || features.isDesktopCapturerEnabled()) {
4649
exports.browserModuleNames.push('desktopCapturer');
4750
}
4851
if (!features || features.isViewApiEnabled()) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { initialize } from './server';
1+
export { initialize, enable } from "./server";
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.initialize = void 0;
3+
exports.enable = exports.initialize = void 0;
44
var server_1 = require("./server");
55
Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return server_1.initialize; } });
6+
Object.defineProperty(exports, "enable", { enumerable: true, get: function () { return server_1.enable; } });
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { WebContents } from 'electron';
2-
export declare const isRemoteModuleEnabled: (contents: WebContents) => any;
2+
export declare const isRemoteModuleEnabled: (contents: WebContents) => boolean | undefined;
3+
export declare function enable(contents: WebContents): void;
34
export declare function initialize(): void;

static/remote/dist/src/main/server.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6-
exports.initialize = exports.isRemoteModuleEnabled = void 0;
6+
exports.initialize = exports.enable = exports.isRemoteModuleEnabled = void 0;
77
const events_1 = require("events");
88
const objects_registry_1 = __importDefault(require("./objects-registry"));
99
const type_utils_1 = require("../common/type-utils");
1010
const electron_1 = require("electron");
1111
const get_electron_binding_1 = require("../common/get-electron-binding");
12+
const { Promise } = global;
1213
const v8Util = get_electron_binding_1.getElectronBinding('v8_util');
14+
const hasWebPrefsRemoteModuleAPI = (() => {
15+
var _a, _b;
16+
const electronVersion = Number((_b = (_a = process.versions.electron) === null || _a === void 0 ? void 0 : _a.split(".")) === null || _b === void 0 ? void 0 : _b[0]);
17+
return Number.isNaN(electronVersion) || electronVersion < 14;
18+
})();
1319
// The internal properties of Function.
1420
const FUNCTION_PROPERTIES = [
1521
'length', 'name', 'arguments', 'caller', 'prototype'
@@ -293,19 +299,23 @@ const isRemoteModuleEnabledImpl = function (contents) {
293299
};
294300
const isRemoteModuleEnabledCache = new WeakMap();
295301
const isRemoteModuleEnabled = function (contents) {
296-
if (!isRemoteModuleEnabledCache.has(contents)) {
302+
if (hasWebPrefsRemoteModuleAPI && !isRemoteModuleEnabledCache.has(contents)) {
297303
isRemoteModuleEnabledCache.set(contents, isRemoteModuleEnabledImpl(contents));
298304
}
299305
return isRemoteModuleEnabledCache.get(contents);
300306
};
301307
exports.isRemoteModuleEnabled = isRemoteModuleEnabled;
308+
function enable(contents) {
309+
isRemoteModuleEnabledCache.set(contents, true);
310+
}
311+
exports.enable = enable;
302312
const handleRemoteCommand = function (channel, handler) {
303313
electron_1.ipcMain.on(channel, (event, contextId, ...args) => {
304314
let returnValue;
305315
if (!exports.isRemoteModuleEnabled(event.sender)) {
306316
event.returnValue = {
307317
type: 'exception',
308-
value: valueToMeta(event.sender, contextId, new Error('@electron/remote is disabled for this WebContents. Set {enableRemoteModule: true} in WebPreferences to enable it.'))
318+
value: valueToMeta(event.sender, contextId, new Error('@electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.'))
309319
};
310320
return;
311321
}
@@ -338,8 +348,6 @@ let initialized = false;
338348
function initialize() {
339349
if (initialized)
340350
throw new Error('@electron/remote has already been initialized');
341-
if (Number(process.versions.electron.split('.')[0]) >= 14)
342-
throw new Error('@electron/remote >= 2.x is required for Electron >= 14. See https://github.com/electron/remote/blob/main/docs/migration-2.md for migration instructions.');
343351
initialized = true;
344352
handleRemoteCommand("REMOTE_BROWSER_WRONG_CONTEXT_ERROR" /* BROWSER_WRONG_CONTEXT_ERROR */, function (event, contextId, passedContextId, id) {
345353
const objectId = [passedContextId, id];
@@ -433,7 +441,8 @@ function initialize() {
433441
return valueToMeta(event.sender, contextId, func(...args), true);
434442
}
435443
catch (error) {
436-
const err = new Error(`Could not call remote function '${func.name || 'anonymous'}'. Check that the function signature is correct. Underlying error: ${error.message}\nUnderlying stack: ${error.stack}\n`);
444+
const err = new Error(`Could not call remote function '${func.name || "anonymous"}'. Check that the function signature is correct. Underlying error: ${error}\n` +
445+
(error instanceof Error ? `Underlying stack: ${error.stack}\n` : ""));
437446
err.cause = error;
438447
throw err;
439448
}
@@ -456,7 +465,8 @@ function initialize() {
456465
return valueToMeta(event.sender, contextId, object[method](...args), true);
457466
}
458467
catch (error) {
459-
const err = new Error(`Could not call remote method '${method}'. Check that the method signature is correct. Underlying error: ${error.message}\nUnderlying stack: ${error.stack}\n`);
468+
const err = new Error(`Could not call remote method '${method}'. Check that the method signature is correct. Underlying error: ${error}` +
469+
(error instanceof Error ? `Underlying stack: ${error.stack}\n` : ""));
460470
err.cause = error;
461471
throw err;
462472
}

static/remote/dist/src/renderer/remote.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const type_utils_1 = require("../common/type-utils");
66
const electron_1 = require("electron");
77
const module_names_1 = require("../common/module-names");
88
const get_electron_binding_1 = require("../common/get-electron-binding");
9+
const { Promise } = global;
910
const callbacksRegistry = new callbacks_registry_1.CallbacksRegistry();
1011
const remoteObjectCache = new Map();
1112
const finalizationRegistry = new FinalizationRegistry((id) => {
@@ -247,6 +248,8 @@ function proxyFunctionProperties(remoteMemberFunction, metaId, name) {
247248
}
248249
// Convert meta data from browser into real value.
249250
function metaToValue(meta) {
251+
if (!meta)
252+
return {};
250253
if (meta.type === 'value') {
251254
return meta.value;
252255
}

0 commit comments

Comments
 (0)