aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/devTools.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/devTools.ts')
-rw-r--r--packages/main/src/devTools.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/main/src/devTools.ts b/packages/main/src/devTools.ts
new file mode 100644
index 0000000..d02bfbf
--- /dev/null
+++ b/packages/main/src/devTools.ts
@@ -0,0 +1,49 @@
1import type { App, BrowserWindow } from 'electron';
2
3/**
4 * Installs the react and redux developer tools extensions.
5 *
6 * We use the redux devtools and connect the mobx store to it with `mst-middlewares`,
7 * because the mobx-state-tree devtools are currently unmaintained.
8 *
9 * @param app The electron application instance.
10 */
11export function installDevToolsExtensions(app: App): void {
12 app.whenReady().then(async () => {
13 const {
14 default: installExtension,
15 REACT_DEVELOPER_TOOLS,
16 REDUX_DEVTOOLS,
17 } = await import('electron-devtools-installer');
18 installExtension(
19 [
20 REACT_DEVELOPER_TOOLS,
21 REDUX_DEVTOOLS,
22 ],
23 {
24 forceDownload: false,
25 loadExtensionOptions: {
26 allowFileAccess: true,
27 },
28 },
29 );
30 }).catch((err) => {
31 console.error('Failed to install devtools extension', err);
32 });
33}
34
35/**
36 * Opens the developer tools while applying a workaround to enable the redux devtools.
37 *
38 * @param browserWindow The browser window to open the devtools in.
39 * @see https://github.com/MarshallOfSound/electron-devtools-installer/issues/195#issuecomment-998872878
40 */
41export function openDevToolsWhenReady(browserWindow: BrowserWindow): void {
42 const { webContents } = browserWindow;
43 webContents.once('dom-ready', () => {
44 webContents.once('devtools-opened', () => {
45 browserWindow?.focus();
46 });
47 webContents.openDevTools();
48 });
49}