From 53f9f2c6214afe8ff80d97e773e486eac71484b0 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Thu, 21 Nov 2024 00:38:09 +0100 Subject: [PATCH] fix: show windows when the app is rendered Signed-off-by: Grigorii K. Shartsev --- src/authentication/authentication.window.js | 4 ++- .../renderer/authentication.main.js | 3 ++ src/help/help.window.js | 6 ++-- src/help/renderer/help.app.js | 3 ++ src/main.js | 32 +++++++++---------- src/talk/renderer/talk.main.js | 3 ++ src/upgrade/renderer/upgrade.app.js | 3 ++ src/upgrade/upgrade.window.js | 6 ++-- src/welcome/welcome.js | 3 ++ src/welcome/welcome.window.js | 4 ++- 10 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/authentication/authentication.window.js b/src/authentication/authentication.window.js index 55b06697..0fcdef39 100644 --- a/src/authentication/authentication.window.js +++ b/src/authentication/authentication.window.js @@ -8,7 +8,7 @@ const { BASE_TITLE, TITLE_BAR_HEIGHT } = require('../constants.js') const { applyContextMenu } = require('../app/applyContextMenu.js') const { getBrowserWindowIcon } = require('../shared/icons.utils.js') const { getAppConfig } = require('../app/AppConfig.ts') -const { getScaledWindowSize } = require('../app/utils.ts') +const { getScaledWindowSize, showWhenWindowMarkedReady } = require('../app/utils.ts') /** * @return {import('electron').BrowserWindow} @@ -53,6 +53,8 @@ function createAuthenticationWindow() { window.loadURL(AUTHENTICATION_WINDOW_WEBPACK_ENTRY) + showWhenWindowMarkedReady(window) + return window } diff --git a/src/authentication/renderer/authentication.main.js b/src/authentication/renderer/authentication.main.js index 5b2c5f21..3536f7fb 100644 --- a/src/authentication/renderer/authentication.main.js +++ b/src/authentication/renderer/authentication.main.js @@ -8,7 +8,10 @@ import '../../shared/assets/global.styles.css' import Vue from 'vue' import AuthenticationApp from './AuthenticationApp.vue' import { setupWebPage } from '../../shared/setupWebPage.js' +import { markWindowReady } from '../../shared/markWindowReady.ts' await setupWebPage() new Vue(AuthenticationApp).$mount('#app') + +markWindowReady() diff --git a/src/help/help.window.js b/src/help/help.window.js index 61e06228..753e4be8 100644 --- a/src/help/help.window.js +++ b/src/help/help.window.js @@ -7,7 +7,7 @@ const { BASE_TITLE } = require('../constants.js') const { BrowserWindow } = require('electron') const { applyExternalLinkHandler } = require('../app/externalLinkHandlers.js') const { getBrowserWindowIcon } = require('../shared/icons.utils.js') -const { getScaledWindowSize } = require('../app/utils.ts') +const { getScaledWindowSize, showWhenWindowMarkedReady } = require('../app/utils.ts') const { applyContextMenu } = require('../app/applyContextMenu.js') /** @@ -44,9 +44,7 @@ function createHelpWindow(parentWindow) { applyExternalLinkHandler(window) applyContextMenu(window) - window.on('ready-to-show', () => { - window.show() - }) + showWhenWindowMarkedReady(window) return window } diff --git a/src/help/renderer/help.app.js b/src/help/renderer/help.app.js index 56a82bc9..aa74e6c2 100644 --- a/src/help/renderer/help.app.js +++ b/src/help/renderer/help.app.js @@ -8,6 +8,7 @@ import './help.styles.css' import Vue, { defineAsyncComponent } from 'vue' import { setupWebPage } from '../../shared/setupWebPage.js' +import { markWindowReady } from '../../shared/markWindowReady.ts' await setupWebPage() @@ -16,3 +17,5 @@ new Vue({ name: 'HelpAppRoot', render: h => h(HelpApp), }).$mount('#app') + +markWindowReady() diff --git a/src/main.js b/src/main.js index c5d64721..c80995bb 100644 --- a/src/main.js +++ b/src/main.js @@ -20,6 +20,7 @@ const { installVueDevtools } = require('./install-vue-devtools.js') const { loadAppConfig, getAppConfig, setAppConfig } = require('./app/AppConfig.ts') const { triggerDownloadUrl } = require('./app/downloads.ts') const { applyTheme } = require('./app/theme.config.ts') +const { showWhenWindowMarkedReady, waitWindowMarkedReady } = require('./app/utils.ts') /** * Parse command line arguments @@ -146,7 +147,7 @@ app.whenReady().then(async () => { // There is no window (possible on macOS) - create if (!mainWindow || mainWindow.isDestroyed()) { mainWindow = createMainWindow() - mainWindow.once('ready-to-show', () => mainWindow.show()) + showWhenWindowMarkedReady(mainWindow) return } @@ -235,7 +236,6 @@ app.whenReady().then(async () => { mainWindow = createWelcomeWindow() createMainWindow = createWelcomeWindow - mainWindow.once('ready-to-show', () => mainWindow.show()) ipcMain.once('appData:receive', async (event, appData) => { const welcomeWindow = mainWindow @@ -256,14 +256,15 @@ app.whenReady().then(async () => { createMainWindow = createAuthenticationWindow } - mainWindow.once('ready-to-show', () => { - // Do not show the main window if it is the Talk Window opened in the background - const isTalkWindow = createMainWindow === createTalkWindow - if (!isTalkWindow || !ARGUMENTS.openInBackground) { - mainWindow.show() - } - welcomeWindow.close() - }) + await waitWindowMarkedReady(mainWindow) + + welcomeWindow.close() + + // Do not show the main window if it is the Talk Window opened in the background + const isTalkWindow = createMainWindow === createTalkWindow + if (!isTalkWindow || !ARGUMENTS.openInBackground) { + mainWindow.show() + } }) let macDockBounceId @@ -289,19 +290,18 @@ app.whenReady().then(async () => { ipcMain.handle('authentication:openLoginWebView', async (event, serverUrl) => openLoginWebView(mainWindow, serverUrl)) - ipcMain.handle('authentication:login', async () => { + ipcMain.handle('authentication:login', () => { mainWindow.close() mainWindow = createTalkWindow() createMainWindow = createTalkWindow - mainWindow.once('ready-to-show', () => mainWindow.show()) + showWhenWindowMarkedReady(mainWindow) }) - ipcMain.handle('authentication:logout', async (event) => { + ipcMain.handle('authentication:logout', async () => { if (createMainWindow === createTalkWindow) { await mainWindow.webContents.session.clearStorageData() const authenticationWindow = createAuthenticationWindow() createMainWindow = createAuthenticationWindow - authenticationWindow.once('ready-to-show', () => authenticationWindow.show()) mainWindow.destroy() mainWindow = authenticationWindow @@ -324,7 +324,7 @@ app.whenReady().then(async () => { isInWindowRelaunch = true mainWindow.destroy() mainWindow = createMainWindow() - mainWindow.once('ready-to-show', () => mainWindow.show()) + showWhenWindowMarkedReady(mainWindow) isInWindowRelaunch = false }) @@ -340,7 +340,7 @@ app.whenReady().then(async () => { // dock icon is clicked and there are no other windows open. // See window-all-closed event handler. mainWindow = createMainWindow() - mainWindow.once('ready-to-show', () => mainWindow.show()) + showWhenWindowMarkedReady(mainWindow) } }) }) diff --git a/src/talk/renderer/talk.main.js b/src/talk/renderer/talk.main.js index 26aead64..dc409143 100644 --- a/src/talk/renderer/talk.main.js +++ b/src/talk/renderer/talk.main.js @@ -11,6 +11,7 @@ import './assets/overrides.css' import 'regenerator-runtime' // TODO: Why isn't it added on bundling import { initTalkHashIntegration } from './init.js' import { setupWebPage } from '../../shared/setupWebPage.js' +import { markWindowReady } from '../../shared/markWindowReady.ts' import { createViewer } from './Viewer/Viewer.js' import { createDesktopApp } from './desktop.app.js' import { registerTalkDesktopSettingsSection } from './Settings/index.ts' @@ -35,3 +36,5 @@ window.OCA.Talk.Desktop.talkRouter.value = window.OCA.Talk.instance.$router registerTalkDesktopSettingsSection() await import('./notifications/notifications.store.js') + +markWindowReady() diff --git a/src/upgrade/renderer/upgrade.app.js b/src/upgrade/renderer/upgrade.app.js index 6d09c4fb..611731d1 100644 --- a/src/upgrade/renderer/upgrade.app.js +++ b/src/upgrade/renderer/upgrade.app.js @@ -8,7 +8,10 @@ import '../../shared/assets/global.styles.css' import Vue from 'vue' import UpgradeApp from './UpgradeApp.vue' import { setupWebPage } from '../../shared/setupWebPage.js' +import { markWindowReady } from '../../shared/markWindowReady.ts' await setupWebPage() new Vue(UpgradeApp).$mount('#app') + +markWindowReady() diff --git a/src/upgrade/upgrade.window.js b/src/upgrade/upgrade.window.js index 25679beb..5a4bc5d1 100644 --- a/src/upgrade/upgrade.window.js +++ b/src/upgrade/upgrade.window.js @@ -7,7 +7,7 @@ const { BASE_TITLE } = require('../constants.js') const { BrowserWindow } = require('electron') const { applyExternalLinkHandler } = require('../app/externalLinkHandlers.js') const { getBrowserWindowIcon } = require('../shared/icons.utils.js') -const { getScaledWindowSize } = require('../app/utils.ts') +const { getScaledWindowSize, showWhenWindowMarkedReady } = require('../app/utils.ts') /** * @@ -38,9 +38,7 @@ function createUpgradeWindow() { applyExternalLinkHandler(window) - window.on('ready-to-show', () => { - window.show() - }) + showWhenWindowMarkedReady(window) return window } diff --git a/src/welcome/welcome.js b/src/welcome/welcome.js index 2ce26812..e5ff7929 100644 --- a/src/welcome/welcome.js +++ b/src/welcome/welcome.js @@ -9,6 +9,7 @@ import { appData } from '../app/AppData.js' import { refetchAppDataIfDirty } from '../app/appData.service.js' import { initGlobals } from '../shared/globals/globals.js' import { applyAxiosInterceptors } from '../shared/setupWebPage.js' +import { markWindowReady } from '../shared/markWindowReady.ts' const quitButton = document.querySelector('.quit') quitButton.addEventListener('click', () => window.TALK_DESKTOP.quit()) @@ -20,6 +21,8 @@ window.TALK_DESKTOP.getSystemInfo().then(os => { } }) +markWindowReady() + appData.restore() initGlobals() diff --git a/src/welcome/welcome.window.js b/src/welcome/welcome.window.js index 75bbdf8e..bee0a685 100644 --- a/src/welcome/welcome.window.js +++ b/src/welcome/welcome.window.js @@ -6,7 +6,7 @@ const { BrowserWindow } = require('electron') const { getBrowserWindowIcon } = require('../shared/icons.utils.js') const { isMac } = require('../app/system.utils.ts') -const { getScaledWindowSize } = require('../app/utils.ts') +const { getScaledWindowSize, showWhenWindowMarkedReady } = require('../app/utils.ts') /** * @return {import('electron').BrowserWindow} @@ -37,6 +37,8 @@ function createWelcomeWindow() { window.loadURL(WELCOME_WINDOW_WEBPACK_ENTRY) + showWhenWindowMarkedReady(window) + return window }