Skip to content

Commit 3a7d7bb

Browse files
committed
feat: install chrome devtools
1 parent 50416d1 commit 3a7d7bb

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

electron/main/app.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const appEnv = process.env.APP_ENV ?? 'production';
1919
const appEnvIsProd = appEnv === 'production';
2020
const appEnvIsDev = appEnv === 'development';
2121

22+
// Only load dev tools when running in development.
23+
const appEnableDevTools = appEnvIsDev && !app.isPackaged;
24+
2225
const appPath = app.getAppPath();
2326
const appElectronPath = path.join(appPath, 'electron');
2427
const appBuildPath = path.join(appElectronPath, 'build');
@@ -65,7 +68,7 @@ const createMainWindow = async (): Promise<void> => {
6568
show: false, // hidden until window loads contents to avoid a blank screen
6669
webPreferences: {
6770
preload: path.join(appPreloadPath, 'index.js'),
68-
devTools: !app.isPackaged,
71+
devTools: appEnableDevTools,
6972
/**
7073
* Security Best Practices
7174
* https://www.electronjs.org/docs/latest/tutorial/security
@@ -114,6 +117,12 @@ const createMainWindow = async (): Promise<void> => {
114117
// Prepare the renderer once the app is ready
115118
app.on('ready', () => {
116119
runInBackground(async () => {
120+
if (appEnableDevTools) {
121+
const { installChromeExtensions } = await import(
122+
'./chrome/install-extension'
123+
);
124+
await installChromeExtensions();
125+
}
117126
await createMainWindow();
118127
});
119128
});
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {
2+
REACT_DEVELOPER_TOOLS,
3+
installExtension,
4+
} from 'electron-extension-installer';
5+
6+
// The recommended module for installing extensions for electron doesn't work.
7+
// Using another one from the community.
8+
// https://github.com/MarshallOfSound/electron-devtools-installer/issues/238#issuecomment-1499578154
9+
10+
export const installChromeExtensions = async (): Promise<void> => {
11+
await installReactDevTools();
12+
};
13+
14+
export const installReactDevTools = async (): Promise<void> => {
15+
await installExtension(REACT_DEVELOPER_TOOLS, {
16+
loadExtensionOptions: {
17+
allowFileAccess: true,
18+
},
19+
});
20+
};

0 commit comments

Comments
 (0)