@@ -3,7 +3,7 @@ const path = require('path');
33const windows : Electron . BrowserWindow [ ] = [ ] ;
44let readyToShowWindowsIds : number [ ] = [ ] ;
55let window , lastOptions , electronSocket ;
6-
6+ let mainWindowURL ;
77export = ( socket : SocketIO . Socket , app : Electron . App ) => {
88 electronSocket = socket ;
99 socket . on ( 'register-browserWindow-ready-to-show' , ( id ) => {
@@ -199,7 +199,19 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
199199 options = { ...options , webPreferences : { nodeIntegration : true } } ;
200200 }
201201
202- window = new BrowserWindow ( options ) ;
202+ // we dont want to recreate the window when watch is ready.
203+ if ( app . commandLine . hasSwitch ( 'watch' ) && app [ 'mainWindowURL' ] === loadUrl ) {
204+ window = app [ 'mainWindow' ] ;
205+ if ( window ) {
206+ window . reload ( ) ;
207+ windows . push ( window ) ;
208+ electronSocket . emit ( 'BrowserWindowCreated' , window . id ) ;
209+ return ;
210+ }
211+ } else {
212+ window = new BrowserWindow ( options ) ;
213+ }
214+
203215 window . on ( 'ready-to-show' , ( ) => {
204216 if ( readyToShowWindowsIds . includes ( window . id ) ) {
205217 readyToShowWindowsIds = readyToShowWindowsIds . filter ( value => value !== window . id ) ;
@@ -245,6 +257,12 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
245257 console . log ( 'auto clear-cache active for new window.' ) ;
246258 }
247259
260+ // set main window url
261+ if ( app [ 'mainWindowURL' ] == undefined || app [ 'mainWindowURL' ] == "" ) {
262+ app [ 'mainWindowURL' ] = loadUrl ;
263+ app [ 'mainWindow' ] = window ;
264+ }
265+
248266 windows . push ( window ) ;
249267 electronSocket . emit ( 'BrowserWindowCreated' , window . id ) ;
250268 } ) ;
@@ -744,6 +762,7 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
744762 getWindowById ( id ) . setBrowserView ( browserView ) ;
745763 } ) ;
746764
765+
747766 function getWindowById ( id : number ) : Electron . BrowserWindow {
748767 for ( let index = 0 ; index < windows . length ; index ++ ) {
749768 const element = windows [ index ] ;
0 commit comments