@@ -14,7 +14,6 @@ import {
14
14
} from '@theia/core/lib/electron-main/electron-main-application' ;
15
15
import { SplashServiceImpl } from '../splash/splash-service-impl' ;
16
16
import { URI } from '@theia/core/shared/vscode-uri' ;
17
- import * as electronRemoteMain from '@theia/core/electron-shared/@electron/remote/main' ;
18
17
import { Deferred } from '@theia/core/lib/common/promise-util' ;
19
18
import * as os from '@theia/core/lib/common/os' ;
20
19
import { Restart } from '@theia/core/lib/electron-common/messaging/electron-messages' ;
@@ -37,7 +36,6 @@ const WORKSPACES = 'workspaces';
37
36
38
37
@injectable ( )
39
38
export class ElectronMainApplication extends TheiaElectronMainApplication {
40
- protected _windows : BrowserWindow [ ] = [ ] ;
41
39
protected startup = false ;
42
40
protected openFilePromise = new Deferred ( ) ;
43
41
@@ -176,102 +174,89 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
176
174
*
177
175
* @param options
178
176
*/
179
- async createWindow (
177
+ async createWindow (
180
178
asyncOptions : MaybePromise < TheiaBrowserWindowOptions > = this . getDefaultTheiaWindowOptions ( )
181
179
) : Promise < BrowserWindow > {
182
- let options = await asyncOptions ;
183
- options = this . avoidOverlap ( options ) ;
184
- let electronWindow : BrowserWindow | undefined ;
185
- if ( this . _windows . length ) {
186
- electronWindow = await super . createWindow ( options ) ;
187
- } else {
188
- const { bounds } = screen . getDisplayNearestPoint (
189
- screen . getCursorScreenPoint ( )
190
- ) ;
191
- const splashHeight = 450 ;
192
- const splashWidth = 600 ;
193
- const splashY = Math . floor ( bounds . y + ( bounds . height - splashHeight ) / 2 ) ;
194
- const splashX = Math . floor ( bounds . x + ( bounds . width - splashWidth ) / 2 ) ;
195
- const splashScreenOpts : BrowserWindowConstructorOptions = {
196
- height : splashHeight ,
197
- width : splashWidth ,
198
- x : splashX ,
199
- y : splashY ,
200
- transparent : true ,
201
- alwaysOnTop : true ,
202
- focusable : false ,
203
- minimizable : false ,
204
- maximizable : false ,
205
- hasShadow : false ,
206
- resizable : false ,
207
- } ;
208
- electronWindow = initSplashScreen (
209
- {
210
- windowOpts : options ,
211
- templateUrl : join (
212
- __dirname ,
213
- '..' ,
214
- '..' ,
215
- '..' ,
216
- 'src' ,
217
- 'electron-main' ,
218
- 'splash' ,
219
- 'static' ,
220
- 'splash.html'
221
- ) ,
222
- delay : 0 ,
223
- minVisible : 2000 ,
224
- splashScreenOpts,
225
- } ,
226
- this . splashService . onCloseRequested
180
+ const createRegularWindow = ! this . windows . size ;
181
+ const electronWindow = await ( createRegularWindow
182
+ ? super . createWindow ( asyncOptions )
183
+ : this . createSplashScreenWindow ( asyncOptions ) ) ;
184
+ if ( createRegularWindow ) {
185
+ electronWindow . webContents . on (
186
+ 'new-window' ,
187
+ ( event , url , frameName , disposition , options ) => {
188
+ if ( frameName === 'serialPlotter' ) {
189
+ event . preventDefault ( ) ;
190
+ Object . assign ( options , {
191
+ width : 800 ,
192
+ minWidth : 620 ,
193
+ height : 500 ,
194
+ minHeight : 320 ,
195
+ x : 100 ,
196
+ y : 100 ,
197
+ webPreferences : {
198
+ devTools : true ,
199
+ nativeWindowOpen : true ,
200
+ openerId : electronWindow ?. webContents . id ,
201
+ } ,
202
+ } ) ;
203
+ event . newGuest = new BrowserWindow ( options ) ;
204
+ event . newGuest . setMenu ( null ) ;
205
+ event . newGuest ?. on ( 'closed' , ( e : any ) => {
206
+ electronWindow ?. webContents . send ( 'CLOSE_CHILD_WINDOW' ) ;
207
+ } ) ;
208
+ event . newGuest ?. loadURL ( url ) ;
209
+ }
210
+ }
227
211
) ;
228
212
}
213
+ return electronWindow ;
214
+ }
229
215
230
- electronWindow . webContents . on (
231
- 'new-window' ,
232
- ( event , url , frameName , disposition , options ) => {
233
- if ( frameName === 'serialPlotter' ) {
234
- event . preventDefault ( ) ;
235
- Object . assign ( options , {
236
- width : 800 ,
237
- minWidth : 620 ,
238
- height : 500 ,
239
- minHeight : 320 ,
240
- x : 100 ,
241
- y : 100 ,
242
- webPreferences : {
243
- devTools : true ,
244
- nativeWindowOpen : true ,
245
- openerId : electronWindow ?. webContents . id ,
246
- } ,
247
- } ) ;
248
- event . newGuest = new BrowserWindow ( options ) ;
249
- event . newGuest . setMenu ( null ) ;
250
- event . newGuest ?. on ( 'closed' , ( e : any ) => {
251
- electronWindow ?. webContents . send ( 'CLOSE_CHILD_WINDOW' ) ;
252
- } ) ;
253
- event . newGuest ?. loadURL ( url ) ;
254
- }
255
- }
216
+ private async createSplashScreenWindow (
217
+ asyncOptions : MaybePromise < TheiaBrowserWindowOptions >
218
+ ) : Promise < BrowserWindow > {
219
+ const options = await asyncOptions ;
220
+ const { bounds } = screen . getDisplayNearestPoint (
221
+ screen . getCursorScreenPoint ( )
222
+ ) ;
223
+ const splashHeight = 450 ;
224
+ const splashWidth = 600 ;
225
+ const splashY = Math . floor ( bounds . y + ( bounds . height - splashHeight ) / 2 ) ;
226
+ const splashX = Math . floor ( bounds . x + ( bounds . width - splashWidth ) / 2 ) ;
227
+ const splashScreenOpts : BrowserWindowConstructorOptions = {
228
+ height : splashHeight ,
229
+ width : splashWidth ,
230
+ x : splashX ,
231
+ y : splashY ,
232
+ transparent : true ,
233
+ alwaysOnTop : true ,
234
+ focusable : false ,
235
+ minimizable : false ,
236
+ maximizable : false ,
237
+ hasShadow : false ,
238
+ resizable : false ,
239
+ } ;
240
+ return initSplashScreen (
241
+ {
242
+ windowOpts : options ,
243
+ templateUrl : join (
244
+ __dirname ,
245
+ '..' ,
246
+ '..' ,
247
+ '..' ,
248
+ 'src' ,
249
+ 'electron-main' ,
250
+ 'splash' ,
251
+ 'static' ,
252
+ 'splash.html'
253
+ ) ,
254
+ delay : 0 ,
255
+ minVisible : 2000 ,
256
+ splashScreenOpts,
257
+ } ,
258
+ this . splashService . onCloseRequested
256
259
) ;
257
-
258
- this . _windows . push ( electronWindow ) ;
259
- electronWindow . on ( 'closed' , ( ) => {
260
- if ( electronWindow ) {
261
- const index = this . _windows . indexOf ( electronWindow ) ;
262
- if ( index === - 1 ) {
263
- console . warn (
264
- `Could not dispose browser window: '${ electronWindow . title } '.`
265
- ) ;
266
- } else {
267
- this . _windows . splice ( index , 1 ) ;
268
- electronWindow = undefined ;
269
- }
270
- }
271
- } ) ;
272
- this . attachClosedWorkspace ( electronWindow ) ;
273
- electronRemoteMain . enable ( electronWindow . webContents ) ;
274
- return electronWindow ;
275
260
}
276
261
277
262
protected async startBackend ( ) : Promise < number > {
@@ -376,6 +361,6 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
376
361
}
377
362
378
363
get browserWindows ( ) : BrowserWindow [ ] {
379
- return this . _windows ;
364
+ return Array . from ( this . windows . values ( ) ) . map ( ( { window } ) => window ) ;
380
365
}
381
366
}
0 commit comments