Update @electron/remote usage for electron v14

This commit is contained in:
Labhansh Agrawal 2021-11-23 09:20:10 +05:30
parent e7acdeac37
commit 4c90d7555c
5 changed files with 15 additions and 11 deletions

View file

@ -10,8 +10,8 @@ if (['--help', '-v', '--version'].includes(process.argv[1])) {
} }
// Enable remote module // Enable remote module
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-var-requires import {initialize as remoteInitialize} from '@electron/remote/main';
require('@electron/remote/main').initialize(); remoteInitialize();
// Native // Native
import {resolve} from 'path'; import {resolve} from 'path';

View file

@ -1,4 +1,4 @@
import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions, Event, WebPreferences} from 'electron'; import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions, Event} from 'electron';
import {isAbsolute, normalize, sep} from 'path'; import {isAbsolute, normalize, sep} from 'path';
import {URL, fileURLToPath} from 'url'; import {URL, fileURLToPath} from 'url';
import {v4 as uuidv4} from 'uuid'; import {v4 as uuidv4} from 'uuid';
@ -14,6 +14,7 @@ import contextMenuTemplate from './contextmenu';
import {execCommand} from '../commands'; import {execCommand} from '../commands';
import {setRendererType, unsetRendererType} from '../utils/renderer-utils'; import {setRendererType, unsetRendererType} from '../utils/renderer-utils';
import {decorateSessionOptions, decorateSessionClass} from '../plugins'; import {decorateSessionOptions, decorateSessionClass} from '../plugins';
import {enable as remoteEnable} from '@electron/remote/main';
export function newWindow( export function newWindow(
options_: BrowserWindowConstructorOptions, options_: BrowserWindowConstructorOptions,
@ -38,12 +39,15 @@ export function newWindow(
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
navigateOnDragDrop: true, navigateOnDragDrop: true,
enableRemoteModule: true,
contextIsolation: false contextIsolation: false
} as WebPreferences, },
...options_ ...options_
}; };
const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(winOpts)); const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(winOpts));
// Enable remote module on this window
remoteEnable(window.webContents);
window.uid = classOpts.uid; window.uid = classOpts.uid;
app.plugins.onWindowClass(window); app.plugins.onWindowClass(window);

View file

@ -1,9 +1,9 @@
import * as remote from '@electron/remote'; import {require as remoteRequire} from '@electron/remote';
import {HyperDispatch} from './hyper'; import {HyperDispatch} from './hyper';
import {closeSearch} from './actions/sessions'; import {closeSearch} from './actions/sessions';
// TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 // TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31
const {getDecoratedKeymaps} = remote.require('./plugins') as typeof import('../app/plugins'); const {getDecoratedKeymaps} = remoteRequire('./plugins') as typeof import('../app/plugins');
let commands: Record<string, (event: any, dispatch: HyperDispatch) => void> = { let commands: Record<string, (event: any, dispatch: HyperDispatch) => void> = {
'editor:search-close': (e, dispatch) => { 'editor:search-close': (e, dispatch) => {

View file

@ -1,8 +1,8 @@
import {ipcRenderer} from 'electron'; import {ipcRenderer} from 'electron';
import * as remote from '@electron/remote'; import {require as remoteRequire} from '@electron/remote';
// TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 // 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'); const plugins = remoteRequire('./plugins') as typeof import('../../app/plugins');
export function getConfig() { export function getConfig() {
return plugins.getDecoratedConfig(); return plugins.getDecoratedConfig();

View file

@ -1,6 +1,6 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair // eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-return */
import * as remote from '@electron/remote'; import {require as remoteRequire} from '@electron/remote';
// TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 // 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'; import {connect as reduxConnect, Options} from 'react-redux';
@ -32,7 +32,7 @@ import IPCChildProcess from './ipc-child-process';
import ChildProcess from 'child_process'; import ChildProcess from 'child_process';
// remote interface to `../plugins` // remote interface to `../plugins`
const plugins = remote.require('./plugins') as typeof import('../../app/plugins'); const plugins = remoteRequire('./plugins') as typeof import('../../app/plugins');
// `require`d modules // `require`d modules
let modules: hyperPlugin[]; let modules: hyperPlugin[];