From b971de0717a66ae6085670fe5d3a469e236a9446 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 26 Apr 2022 16:55:57 +0200 Subject: refactor: config file saving and debugging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce the number of dependencies and the amount of code running in a security sensitive context. Instead of a deep comparison, we just compare the serialized versions of the config files. Signed-off-by: Kristóf Marussy --- .../src/infrastructure/electron/impl/devTools.ts | 43 +++++++++------------- .../infrastructure/electron/impl/hardenSession.ts | 14 ++++++- 2 files changed, 30 insertions(+), 27 deletions(-) (limited to 'packages/main/src/infrastructure/electron/impl') diff --git a/packages/main/src/infrastructure/electron/impl/devTools.ts b/packages/main/src/infrastructure/electron/impl/devTools.ts index 10f4545..6db88d1 100644 --- a/packages/main/src/infrastructure/electron/impl/devTools.ts +++ b/packages/main/src/infrastructure/electron/impl/devTools.ts @@ -18,34 +18,32 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import type { BrowserWindow } from 'electron'; +import { app, type BrowserWindow } from 'electron'; + +/* eslint-disable + import/no-extraneous-dependencies, + global-require, + @typescript-eslint/no-var-requires, + unicorn/prefer-module -- + Hack to lazily require a CJS module from an ES module transpiled into a CJS module. +*/ /** - * URL prefixes Sophie is allowed load in dev mode. - * - * In dev mode, in addition to the application itself, - * Sophie must be able do download and load the devtools and related extensions, - * so we have to make exceptions in the UI process request filter. + * Makes sure we use a separate data dir for development. */ -export const DEVMODE_ALLOWED_URL_PREFIXES = [ - 'chrome-extension:', - 'devtools:', - 'https://clients2.google.com/service/update2/crx', - 'https://clients2.googleusercontent.com/crx', -]; +export function ensureDevDataDir(): void { + // Use alternative directory when debugging to avoid clobbering the main installation. + app.setPath('userData', `${app.getPath('userData')}-dev`); + const userData = app.getPath('userData'); + const mkdirp = require('mkdirp') as typeof import('mkdirp'); + mkdirp.sync(userData); +} /** * Enables using source maps for node stack traces. */ export function enableStacktraceSourceMaps(): void { const sourceMapSupport = - /* eslint-disable-next-line - import/no-extraneous-dependencies, - global-require, - @typescript-eslint/no-var-requires, - unicorn/prefer-module -- - Hack to lazily require a CJS module from an ES module transpiled into a CJS module. - */ require('source-map-support') as typeof import('source-map-support'); sourceMapSupport.install(); } @@ -61,13 +59,6 @@ export async function installDevToolsExtensions(): Promise { default: installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS, - /* eslint-disable-next-line - import/no-extraneous-dependencies, - global-require, - @typescript-eslint/no-var-requires, - unicorn/prefer-module -- - Hack to lazily require a CJS module from an ES module transpiled into a CJS module. - */ } = require('electron-devtools-installer') as typeof import('electron-devtools-installer'); await installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS], { forceDownload: false, diff --git a/packages/main/src/infrastructure/electron/impl/hardenSession.ts b/packages/main/src/infrastructure/electron/impl/hardenSession.ts index 10b694a..53675a7 100644 --- a/packages/main/src/infrastructure/electron/impl/hardenSession.ts +++ b/packages/main/src/infrastructure/electron/impl/hardenSession.ts @@ -25,7 +25,19 @@ import type { Session } from 'electron'; import { getLogger } from '../../../utils/log'; import type Resources from '../../resources/Resources'; -import { DEVMODE_ALLOWED_URL_PREFIXES } from './devTools'; +/** + * URL prefixes Sophie is allowed load in dev mode. + * + * In dev mode, in addition to the application itself, + * Sophie must be able do download and load the devtools and related extensions, + * so we have to make exceptions in the UI process request filter. + */ +export const DEVMODE_ALLOWED_URL_PREFIXES = [ + 'chrome-extension:', + 'devtools:', + 'https://clients2.google.com/service/update2/crx', + 'https://clients2.googleusercontent.com/crx', +]; const log = getLogger('hardenSession'); -- cgit v1.2.3-70-g09d2