File tree Expand file tree Collapse file tree
apps/electron-backend/src/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -153,6 +153,17 @@ describe('Electron app security helpers', () => {
153153 ) . toBeLessThan ( mainWindow . loadFile . mock . invocationCallOrder [ 0 ] ) ;
154154 } ) ;
155155
156+ it ( 'opens DevTools by default for packaged renderer diagnostics' , async ( ) => {
157+ const appInternals = getAppInternals ( ) ;
158+ const mainWindow = createMockMainWindow ( ) ;
159+ appInternals . mainWindow = mainWindow ;
160+ ( electronApp as unknown as { isPackaged : boolean } ) . isPackaged = true ;
161+
162+ await appInternals . loadMainWindow ( ) ;
163+
164+ expect ( mainWindow . webContents . openDevTools ) . toHaveBeenCalledTimes ( 1 ) ;
165+ } ) ;
166+
156167 it ( 'continues packaged renderer loading when Electron service worker cleanup fails' , async ( ) => {
157168 const appInternals = getAppInternals ( ) ;
158169 const mainWindow = createMockMainWindow ( ) ;
Original file line number Diff line number Diff line change @@ -203,7 +203,13 @@ export default class App {
203203 static BrowserWindow ;
204204
205205 private static shouldOpenDevTools ( ) {
206- return process . env . ELECTRON_OPEN_DEVTOOLS === '1' ;
206+ return process . env . ELECTRON_OPEN_DEVTOOLS === '1' || app . isPackaged ;
207+ }
208+
209+ private static openDevToolsIfRequested ( ) : void {
210+ if ( App . shouldOpenDevTools ( ) ) {
211+ App . mainWindow . webContents . openDevTools ( ) ;
212+ }
207213 }
208214
209215 public static isDevelopmentMode ( ) {
@@ -415,13 +421,15 @@ export default class App {
415421 const loadPromise = App . mainWindow . loadURL (
416422 `http://localhost:${ rendererAppPort } `
417423 ) ;
418- if ( App . shouldOpenDevTools ( ) ) {
419- App . mainWindow . webContents . openDevTools ( ) ;
420- }
424+ App . openDevToolsIfRequested ( ) ;
421425 await loadPromise ;
422426 } else {
423427 await clearElectronServiceWorkerStorage ( ) ;
424- await App . mainWindow . loadFile ( getPackagedRendererIndexPath ( ) ) ;
428+ const loadPromise = App . mainWindow . loadFile (
429+ getPackagedRendererIndexPath ( )
430+ ) ;
431+ App . openDevToolsIfRequested ( ) ;
432+ await loadPromise ;
425433 }
426434 }
427435
You can’t perform that action at this time.
0 commit comments