From a6ed744b82b123f8ddd4ca4b7c76bed8657d1165 Mon Sep 17 00:00:00 2001 From: claude-bot Date: Wed, 6 May 2026 05:03:21 +0900 Subject: [PATCH] Fix launcher startup bootstrap race --- app/assets/js/scripts/settings.js | 2 +- app/assets/js/scripts/uibinder.js | 39 ++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index ea82a65..ae2a03d 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -664,7 +664,7 @@ function populateAuthAccounts(){ if(authKeys.length === 0){ return } - const selectedUUID = ConfigManager.getSelectedAccount().uuid + const selectedUUID = ConfigManager.getSelectedAccount()?.uuid ?? null let microsoftAuthAccountStr = '' let mojangAuthAccountStr = '' diff --git a/app/assets/js/scripts/uibinder.js b/app/assets/js/scripts/uibinder.js index 323849e..b9c341f 100644 --- a/app/assets/js/scripts/uibinder.js +++ b/app/assets/js/scripts/uibinder.js @@ -4,6 +4,7 @@ */ // Requirements const path = require('path') +const { LoggerUtil } = require('helios-core') const { Type } = require('helios-distribution-types') const AuthManager = require('./assets/js/authmanager') @@ -12,6 +13,10 @@ const { DistroAPI } = require('./assets/js/distromanager') let rscShouldLoad = false let fatalStartupError = false +let mainUiBootstrapStarted = false +let mainUiBootstrapped = false + +const loggerUIBinder = LoggerUtil.getLogger('UIBinder') // Mapping of each view to their container IDs. const VIEWS = { @@ -107,6 +112,28 @@ async function showMainUI(data){ }, 750) } +async function bootstrapMainUI(source){ + if(mainUiBootstrapped || mainUiBootstrapStarted){ + return + } + + mainUiBootstrapStarted = true + loggerUIBinder.info(`Bootstrapping main UI from ${source}.`) + + try { + const data = await DistroAPI.getDistribution() + syncModConfigurations(data) + ensureJavaSettings(data) + await showMainUI(data) + mainUiBootstrapped = true + loggerUIBinder.info(`Main UI bootstrap succeeded from ${source}.`) + } catch (error) { + loggerUIBinder.error(`Main UI bootstrap failed from ${source}.`, error) + } finally { + mainUiBootstrapStarted = false + } +} + function showFatalStartupError(){ setTimeout(() => { $('#loadingContainer').fadeOut(250, () => { @@ -422,11 +449,14 @@ document.addEventListener('readystatechange', async () => { if(rscShouldLoad){ rscShouldLoad = false if(!fatalStartupError){ - const data = await DistroAPI.getDistribution() - await showMainUI(data) + await bootstrapMainUI('readystatechange-event') } else { showFatalStartupError() } + } else if(document.readyState === 'complete' && !fatalStartupError){ + setTimeout(() => { + bootstrapMainUI('readystatechange-fallback') + }, 0) } } @@ -435,11 +465,8 @@ document.addEventListener('readystatechange', async () => { // Actions that must be performed after the distribution index is downloaded. ipcRenderer.on('distributionIndexDone', async (event, res) => { if(res) { - const data = await DistroAPI.getDistribution() - syncModConfigurations(data) - ensureJavaSettings(data) if(document.readyState === 'interactive' || document.readyState === 'complete'){ - await showMainUI(data) + await bootstrapMainUI('distributionIndexDone') } else { rscShouldLoad = true }