aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/infrastructure/electron/impl/devTools.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/infrastructure/electron/impl/devTools.ts')
-rw-r--r--packages/main/src/infrastructure/electron/impl/devTools.ts94
1 files changed, 94 insertions, 0 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/devTools.ts b/packages/main/src/infrastructure/electron/impl/devTools.ts
new file mode 100644
index 0000000..10f4545
--- /dev/null
+++ b/packages/main/src/infrastructure/electron/impl/devTools.ts
@@ -0,0 +1,94 @@
1/*
2 * Copyright (C) 2021-2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import type { BrowserWindow } from 'electron';
22
23/**
24 * URL prefixes Sophie is allowed load in dev mode.
25 *
26 * In dev mode, in addition to the application itself,
27 * Sophie must be able do download and load the devtools and related extensions,
28 * so we have to make exceptions in the UI process request filter.
29 */
30export const DEVMODE_ALLOWED_URL_PREFIXES = [
31 'chrome-extension:',
32 'devtools:',
33 'https://clients2.google.com/service/update2/crx',
34 'https://clients2.googleusercontent.com/crx',
35];
36
37/**
38 * Enables using source maps for node stack traces.
39 */
40export function enableStacktraceSourceMaps(): void {
41 const sourceMapSupport =
42 /* eslint-disable-next-line
43 import/no-extraneous-dependencies,
44 global-require,
45 @typescript-eslint/no-var-requires,
46 unicorn/prefer-module --
47 Hack to lazily require a CJS module from an ES module transpiled into a CJS module.
48 */
49 require('source-map-support') as typeof import('source-map-support');
50 sourceMapSupport.install();
51}
52
53/**
54 * Installs the react and redux developer tools extensions.
55 *
56 * We use the redux devtools and connect the mobx store to it with `mst-middlewares`,
57 * because the mobx-state-tree devtools are currently unmaintained.
58 */
59export async function installDevToolsExtensions(): Promise<void> {
60 const {
61 default: installExtension,
62 REACT_DEVELOPER_TOOLS,
63 REDUX_DEVTOOLS,
64 /* eslint-disable-next-line
65 import/no-extraneous-dependencies,
66 global-require,
67 @typescript-eslint/no-var-requires,
68 unicorn/prefer-module --
69 Hack to lazily require a CJS module from an ES module transpiled into a CJS module.
70 */
71 } = require('electron-devtools-installer') as typeof import('electron-devtools-installer');
72 await installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS], {
73 forceDownload: false,
74 loadExtensionOptions: {
75 allowFileAccess: true,
76 },
77 });
78}
79
80/**
81 * Opens the developer tools while applying a workaround to enable the redux devtools.
82 *
83 * @param browserWindow The browser window to open the devtools in.
84 * @see https://github.com/MarshallOfSound/electron-devtools-installer/issues/195#issuecomment-998872878
85 */
86export function openDevToolsWhenReady(browserWindow: BrowserWindow): void {
87 const { webContents } = browserWindow;
88 webContents.once('dom-ready', () => {
89 webContents.once('devtools-opened', () => {
90 browserWindow?.focus();
91 });
92 webContents.openDevTools();
93 });
94}