Fix launcher startup bootstrap race
Some checks failed
Build / release (macos-latest) (push) Has been cancelled
Build / release (ubuntu-latest) (push) Has been cancelled
Build / release (windows-latest) (push) Has been cancelled
Windows Smoke Test / windows-smoke (push) Has been cancelled

This commit is contained in:
2026-05-06 05:03:21 +09:00
parent 20677380b9
commit a6ed744b82
2 changed files with 34 additions and 7 deletions

View File

@@ -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 = ''

View File

@@ -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
}