diff --git a/electron/main-window.ts b/electron/main-window.ts index 42135796e3..79e087887f 100644 --- a/electron/main-window.ts +++ b/electron/main-window.ts @@ -78,6 +78,8 @@ export const createWindow = ({ scrollBounce: true, webSecurity: !IS_DEV, nodeIntegration: true, + // NOTE: will be deprecated with v10 + enableRemoteModule: true }, icon: ICONS_FOLDER + '/icon_256x256.png' }); diff --git a/package.json b/package.json index 024a8f37b6..e47b96d39a 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "conventional-changelog-cli": "^2.0.21", "core-js": "^3.1.3", "cross-env": "^7.0.2", - "electron": "^9.1.1", + "electron": "^10.1.0", "electron-builder": "^22.7.0", "electron-notarize": "^1.0.0", "electron-reload": "^1.2.5", diff --git a/src/app/core/electron/electron.service.ts b/src/app/core/electron/electron.service.ts index 5fcbed3ccd..543ed0fcc5 100644 --- a/src/app/core/electron/electron.service.ts +++ b/src/app/core/electron/electron.service.ts @@ -3,6 +3,8 @@ import { Injectable } from '@angular/core'; // the resulting javascript file will look as if you never imported the module at all. import { ipcRenderer, remote, shell, webFrame } from 'electron'; import { IS_ELECTRON } from '../../app.constants'; +import { getElectron } from '../../util/get-electron'; +import * as ElectronRenderer from 'electron/renderer'; @Injectable({providedIn: 'root'}) export class ElectronService { @@ -16,11 +18,12 @@ export class ElectronService { constructor() { // Conditional imports if (IS_ELECTRON) { - const electron = window.require('electron'); + const electron = getElectron() as typeof ElectronRenderer; this.ipcRenderer = electron.ipcRenderer; this.webFrame = electron.webFrame; this.remote = electron.remote; - this.shell = electron.shell; + // NOTE: works for non-sandboxed electron only + this.shell = (electron as any).shell; } // NOTE: useful in case we want to disable the node integration diff --git a/src/app/features/config/form-cfgs/automatic-backups-form.const.ts b/src/app/features/config/form-cfgs/automatic-backups-form.const.ts index 1bd79ed38d..039850ccdc 100644 --- a/src/app/features/config/form-cfgs/automatic-backups-form.const.ts +++ b/src/app/features/config/form-cfgs/automatic-backups-form.const.ts @@ -3,8 +3,9 @@ import { ConfigFormSection, LocalBackupConfig } from '../global-config.model'; import { T } from '../../../t.const'; import { getElectron } from '../../../util/get-electron'; import { IS_ELECTRON } from '../../../app.constants'; +import * as ElectronRenderer from 'electron/renderer'; -const backupPath = IS_ELECTRON && `${(getElectron() as Electron.RendererInterface).remote.app.getPath('userData')}/backups`; +const backupPath = IS_ELECTRON && `${(getElectron() as typeof ElectronRenderer).remote.app.getPath('userData')}/backups`; export const AUTOMATIC_BACKUPS_FORM: ConfigFormSection = { isElectronOnly: true, diff --git a/src/app/util/get-electron.ts b/src/app/util/get-electron.ts index 93af57fe75..114cf4c4ad 100644 --- a/src/app/util/get-electron.ts +++ b/src/app/util/get-electron.ts @@ -1,5 +1,7 @@ +import * as ElectronRenderer from 'electron/renderer'; + let _electron: any = null; -export const getElectron = (): Electron.RendererInterface | null => { +export const getElectron = (): typeof ElectronRenderer | null => { // tslint:disable-next-line if (window['require']) { _electron = window.require('electron'); diff --git a/yarn.lock b/yarn.lock index 958b18a4b6..49ff3a0f11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4543,10 +4543,10 @@ electron-window-state@^5.0.3: jsonfile "^4.0.0" mkdirp "^0.5.1" -electron@^9.1.1: - version "9.1.1" - resolved "https://registry.yarnpkg.com/electron/-/electron-9.1.1.tgz#d52c9873be4113287c3eb2b02f85bad6644b100e" - integrity sha512-BYvroBLV9x7G4iN33P/IxeZqwjl62/9VuBAF1CoM0m6OeheaiLog1ZMKLlCqVXycJvvrAvLHc454DDEmwnqqhA== +electron@^10.1.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/electron/-/electron-10.1.0.tgz#3559182545dc76e20d9764d183d555415d55c250" + integrity sha512-DyS6WhQ59+ZXQsI1EkpsYkOXFt0Xbp+mbxPTJS9A7O21r3JDzaTC+1Jxz7g6J+Sbi9Y7UFdRs0tn/vqhHJx2gA== dependencies: "@electron/get" "^1.0.1" "@types/node" "^12.0.12"