@@ -19,6 +19,7 @@ const { createWelcomeWindow } = require('./welcome/welcome.window.js')
1919const { installVueDevtools } = require ( './install-vue-devtools.js' )
2020const { loadAppConfig, getAppConfig, setAppConfig } = require ( './app/AppConfig.ts' )
2121const { triggerDownloadUrl } = require ( './app/downloads.ts' )
22+ const { showWhenWindowMarkedReady, waitWindowMarkedReady } = require ( './app/utils.ts' )
2223
2324/**
2425 * Parse command line arguments
@@ -144,7 +145,7 @@ app.whenReady().then(async () => {
144145 // There is no window (possible on macOS) - create
145146 if ( ! mainWindow || mainWindow . isDestroyed ( ) ) {
146147 mainWindow = createMainWindow ( )
147- mainWindow . once ( 'ready-to-show' , ( ) => mainWindow . show ( ) )
148+ showWhenWindowMarkedReady ( mainWindow )
148149 return
149150 }
150151
@@ -233,7 +234,6 @@ app.whenReady().then(async () => {
233234
234235 mainWindow = createWelcomeWindow ( )
235236 createMainWindow = createWelcomeWindow
236- mainWindow . once ( 'ready-to-show' , ( ) => mainWindow . show ( ) )
237237
238238 ipcMain . once ( 'appData:receive' , async ( event , appData ) => {
239239 const welcomeWindow = mainWindow
@@ -254,14 +254,15 @@ app.whenReady().then(async () => {
254254 createMainWindow = createAuthenticationWindow
255255 }
256256
257- mainWindow . once ( 'ready-to-show' , ( ) => {
258- // Do not show the main window if it is the Talk Window opened in the background
259- const isTalkWindow = createMainWindow === createTalkWindow
260- if ( ! isTalkWindow || ! ARGUMENTS . openInBackground ) {
261- mainWindow . show ( )
262- }
263- welcomeWindow . close ( )
264- } )
257+ await waitWindowMarkedReady ( mainWindow )
258+
259+ welcomeWindow . close ( )
260+
261+ // Do not show the main window if it is the Talk Window opened in the background
262+ const isTalkWindow = createMainWindow === createTalkWindow
263+ if ( ! isTalkWindow || ! ARGUMENTS . openInBackground ) {
264+ mainWindow . show ( )
265+ }
265266 } )
266267
267268 let macDockBounceId
@@ -287,19 +288,18 @@ app.whenReady().then(async () => {
287288
288289 ipcMain . handle ( 'authentication:openLoginWebView' , async ( event , serverUrl ) => openLoginWebView ( mainWindow , serverUrl ) )
289290
290- ipcMain . handle ( 'authentication:login' , async ( ) => {
291+ ipcMain . handle ( 'authentication:login' , ( ) => {
291292 mainWindow . close ( )
292293 mainWindow = createTalkWindow ( )
293294 createMainWindow = createTalkWindow
294- mainWindow . once ( 'ready-to-show' , ( ) => mainWindow . show ( ) )
295+ showWhenWindowMarkedReady ( mainWindow )
295296 } )
296297
297- ipcMain . handle ( 'authentication:logout' , async ( event ) => {
298+ ipcMain . handle ( 'authentication:logout' , async ( ) => {
298299 if ( createMainWindow === createTalkWindow ) {
299300 await mainWindow . webContents . session . clearStorageData ( )
300301 const authenticationWindow = createAuthenticationWindow ( )
301302 createMainWindow = createAuthenticationWindow
302- authenticationWindow . once ( 'ready-to-show' , ( ) => authenticationWindow . show ( ) )
303303
304304 mainWindow . destroy ( )
305305 mainWindow = authenticationWindow
@@ -322,7 +322,7 @@ app.whenReady().then(async () => {
322322 isInWindowRelaunch = true
323323 mainWindow . destroy ( )
324324 mainWindow = createMainWindow ( )
325- mainWindow . once ( 'ready-to-show' , ( ) => mainWindow . show ( ) )
325+ showWhenWindowMarkedReady ( mainWindow )
326326 isInWindowRelaunch = false
327327 } )
328328
@@ -338,7 +338,7 @@ app.whenReady().then(async () => {
338338 // dock icon is clicked and there are no other windows open.
339339 // See window-all-closed event handler.
340340 mainWindow = createMainWindow ( )
341- mainWindow . once ( 'ready-to-show' , ( ) => mainWindow . show ( ) )
341+ showWhenWindowMarkedReady ( mainWindow )
342342 }
343343 } )
344344} )
0 commit comments