feat: electron upgrade - 18.0.3 => 20.2.0

This commit is contained in:
Amadou Ada DIENE
2022-09-23 18:55:41 +02:00
committed by DIENE
parent fa6222a1a8
commit f1fce63e24
8 changed files with 4356 additions and 10416 deletions

View File

@@ -31,6 +31,11 @@ export class Window {
// Isolate window context to protect against prototype pollution
// except in e2e test when that access is required
contextIsolation: global.appConfig.isContextIsolation,
// Introduced in Electron 20 and enabled by default
// Among others security constraints, it prevents from required
// CommonJS modules imports into preload script
// which is not bundled yet in dev mode
sandbox: global.appConfig.isSandbox,
// Use a preload script to enhance security
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},

View File

@@ -1,4 +1,4 @@
// To secure user platform when running renderer process stuff,
/*/ To secure user platform when running renderer process stuff,
// Node.JS and Electron APIs are only available in this script
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
import { WindowApi, WindowApiConst } from 'shared-lib';
@@ -31,6 +31,27 @@ if (process.env.X_NODE_ENV === 'e2e-test') {
// ContextBridge API can only be used when contextIsolation is enabled
// which is normally the case except in e2e test mode
contextBridge.exposeInMainWorld('api', windowApi);
}
}*/
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
import { WindowApiConst } from 'shared-lib';
contextBridge.exposeInMainWorld('api', {
node: () => process.versions.node,
chrome: () => process.versions.chrome,
electron: () => process.versions.electron,
send: <In>(channel: string, input: In) => {
if (WindowApiConst.SENDING_SAFE_CHANNELS.includes(channel)) {
ipcRenderer.send(channel, input);
}
},
receive: <Out>(channel: string, callback: (output: Out) => void) => {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (_event: IpcRendererEvent, ...parameters: any[]) =>
callback(parameters[0])
);
},
// we can also expose variables, not just functions
});
console.log('The preload script has been injected successfully.');

View File

@@ -17,6 +17,9 @@ export interface AppConfig {
/** Tells if `contextIsolation` and `worldSafeExecuteJavaScript` webPreferences are enabled */
isContextIsolation: boolean;
/** Tells if `isSandbox` webPreference is enabled */
isSandbox: boolean;
/** Tells if `isEnableRemoteModule` webPreference is enabled */
isEnableRemoteModule: boolean;