Fix launcher startup bootstrap race
This commit is contained in:
@@ -664,7 +664,7 @@ function populateAuthAccounts(){
|
|||||||
if(authKeys.length === 0){
|
if(authKeys.length === 0){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const selectedUUID = ConfigManager.getSelectedAccount().uuid
|
const selectedUUID = ConfigManager.getSelectedAccount()?.uuid ?? null
|
||||||
|
|
||||||
let microsoftAuthAccountStr = ''
|
let microsoftAuthAccountStr = ''
|
||||||
let mojangAuthAccountStr = ''
|
let mojangAuthAccountStr = ''
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
// Requirements
|
// Requirements
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const { LoggerUtil } = require('helios-core')
|
||||||
const { Type } = require('helios-distribution-types')
|
const { Type } = require('helios-distribution-types')
|
||||||
|
|
||||||
const AuthManager = require('./assets/js/authmanager')
|
const AuthManager = require('./assets/js/authmanager')
|
||||||
@@ -12,6 +13,10 @@ const { DistroAPI } = require('./assets/js/distromanager')
|
|||||||
|
|
||||||
let rscShouldLoad = false
|
let rscShouldLoad = false
|
||||||
let fatalStartupError = false
|
let fatalStartupError = false
|
||||||
|
let mainUiBootstrapStarted = false
|
||||||
|
let mainUiBootstrapped = false
|
||||||
|
|
||||||
|
const loggerUIBinder = LoggerUtil.getLogger('UIBinder')
|
||||||
|
|
||||||
// Mapping of each view to their container IDs.
|
// Mapping of each view to their container IDs.
|
||||||
const VIEWS = {
|
const VIEWS = {
|
||||||
@@ -107,6 +112,28 @@ async function showMainUI(data){
|
|||||||
}, 750)
|
}, 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(){
|
function showFatalStartupError(){
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$('#loadingContainer').fadeOut(250, () => {
|
$('#loadingContainer').fadeOut(250, () => {
|
||||||
@@ -422,11 +449,14 @@ document.addEventListener('readystatechange', async () => {
|
|||||||
if(rscShouldLoad){
|
if(rscShouldLoad){
|
||||||
rscShouldLoad = false
|
rscShouldLoad = false
|
||||||
if(!fatalStartupError){
|
if(!fatalStartupError){
|
||||||
const data = await DistroAPI.getDistribution()
|
await bootstrapMainUI('readystatechange-event')
|
||||||
await showMainUI(data)
|
|
||||||
} else {
|
} else {
|
||||||
showFatalStartupError()
|
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.
|
// Actions that must be performed after the distribution index is downloaded.
|
||||||
ipcRenderer.on('distributionIndexDone', async (event, res) => {
|
ipcRenderer.on('distributionIndexDone', async (event, res) => {
|
||||||
if(res) {
|
if(res) {
|
||||||
const data = await DistroAPI.getDistribution()
|
|
||||||
syncModConfigurations(data)
|
|
||||||
ensureJavaSettings(data)
|
|
||||||
if(document.readyState === 'interactive' || document.readyState === 'complete'){
|
if(document.readyState === 'interactive' || document.readyState === 'complete'){
|
||||||
await showMainUI(data)
|
await bootstrapMainUI('distributionIndexDone')
|
||||||
} else {
|
} else {
|
||||||
rscShouldLoad = true
|
rscShouldLoad = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user