Fix launcher startup bootstrap race
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user