From 832b51e1f354843221e4223f5121b17ffda55d2b Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Tue, 7 Sep 2021 11:32:49 +0000 Subject: [PATCH] Use @electron/remote module --- app/index.ts | 4 ++++ app/package.json | 1 + app/ui/window.ts | 4 ++-- app/yarn.lock | 5 +++++ lib/command-registry.ts | 2 +- lib/utils/config.ts | 3 ++- lib/utils/plugins.ts | 2 +- package.json | 1 + yarn.lock | 5 +++++ 9 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/index.ts b/app/index.ts index b9adc620..e6f6c7f5 100644 --- a/app/index.ts +++ b/app/index.ts @@ -9,6 +9,10 @@ if (['--help', '-v', '--version'].includes(process.argv[1])) { process.exit(); } +// Enable remote module +// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-var-requires +require('@electron/remote/main').initialize(); + // Native import {resolve} from 'path'; diff --git a/app/package.json b/app/package.json index e6b17389..ca7e9e05 100644 --- a/app/package.json +++ b/app/package.json @@ -10,6 +10,7 @@ }, "repository": "zeit/hyper", "dependencies": { + "@electron/remote": "2.0.1", "async-retry": "1.3.3", "chokidar": "^3.5.2", "color": "4.0.1", diff --git a/app/ui/window.ts b/app/ui/window.ts index 28dccde2..a4de3ebb 100644 --- a/app/ui/window.ts +++ b/app/ui/window.ts @@ -1,4 +1,4 @@ -import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions, Event} from 'electron'; +import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions, Event, WebPreferences} from 'electron'; import {isAbsolute, normalize, sep} from 'path'; import {URL, fileURLToPath} from 'url'; import {v4 as uuidv4} from 'uuid'; @@ -40,7 +40,7 @@ export function newWindow( navigateOnDragDrop: true, enableRemoteModule: true, contextIsolation: false - }, + } as WebPreferences, ...options_ }; const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(winOpts)); diff --git a/app/yarn.lock b/app/yarn.lock index 90ec4958..f45b4b47 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@electron/remote@2.0.1": + version "2.0.1" + resolved "https://registry.npmjs.org/@electron/remote/-/remote-2.0.1.tgz#810cbc595a21f0f94641eb2d7e8264063a3f84de" + integrity sha512-bGX4/yB2bPZwXm1DsxgoABgH0Cz7oFtXJgkerB8VrStYdTyvhGAULzNLRn9rVmeAuC3VUDXaXpZIlZAZHpsLIA== + "@types/semver@^7.3.8": version "7.3.8" resolved "https://registry.npmjs.org/@types/semver/-/semver-7.3.8.tgz#508a27995498d7586dcecd77c25e289bfaf90c59" diff --git a/lib/command-registry.ts b/lib/command-registry.ts index 8ec3b49d..9808aad1 100644 --- a/lib/command-registry.ts +++ b/lib/command-registry.ts @@ -1,4 +1,4 @@ -import {remote} from 'electron'; +import * as remote from '@electron/remote'; import {HyperDispatch} from './hyper'; import {closeSearch} from './actions/sessions'; // TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 diff --git a/lib/utils/config.ts b/lib/utils/config.ts index 44cf79d1..18040c68 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -1,4 +1,5 @@ -import {ipcRenderer, remote} from 'electron'; +import {ipcRenderer} from 'electron'; +import * as remote from '@electron/remote'; // TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 const plugins = remote.require('./plugins') as typeof import('../../app/plugins'); diff --git a/lib/utils/plugins.ts b/lib/utils/plugins.ts index 3c5b95c2..8c320c3a 100644 --- a/lib/utils/plugins.ts +++ b/lib/utils/plugins.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line eslint-comments/disable-enable-pair /* eslint-disable @typescript-eslint/no-unsafe-return */ -import {remote} from 'electron'; +import * as remote from '@electron/remote'; // TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 import {connect as reduxConnect, Options} from 'react-redux'; diff --git a/package.json b/package.json index acba78ac..92449893 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "email": "team@zeit.co" }, "dependencies": { + "@electron/remote": "2.0.1", "args": "5.0.1", "chalk": "4.1.2", "color": "4.0.1", diff --git a/yarn.lock b/yarn.lock index 90010ddd..a6bcfb55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -569,6 +569,11 @@ global-agent "^2.0.2" global-tunnel-ng "^2.7.1" +"@electron/remote@2.0.1": + version "2.0.1" + resolved "https://registry.npmjs.org/@electron/remote/-/remote-2.0.1.tgz#810cbc595a21f0f94641eb2d7e8264063a3f84de" + integrity sha512-bGX4/yB2bPZwXm1DsxgoABgH0Cz7oFtXJgkerB8VrStYdTyvhGAULzNLRn9rVmeAuC3VUDXaXpZIlZAZHpsLIA== + "@electron/universal@1.0.5": version "1.0.5" resolved "https://registry.npmjs.org/@electron/universal/-/universal-1.0.5.tgz#b812340e4ef21da2b3ee77b2b4d35c9b86defe37"