SkirdaElectronLauncher/app/assets/js/preloader.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-12-25 03:17:30 +00:00
const {ipcRenderer} = require('electron')
const fs = require('fs-extra')
const os = require('os')
const path = require('path')
2022-12-25 03:17:30 +00:00
const ConfigManager = require('./configmanager')
const { DistroAPI } = require('./distromanager')
2022-12-25 03:17:30 +00:00
const LangLoader = require('./langloader')
const { LoggerUtil } = require('helios-core')
// eslint-disable-next-line no-unused-vars
const { HeliosDistribution } = require('helios-core/common')
2022-12-25 03:17:30 +00:00
const logger = LoggerUtil.getLogger('Preloader')
logger.info('Loading..')
// Load ConfigManager
ConfigManager.load()
2023-02-25 08:28:40 +00:00
// Yuck!
// TODO Fix this
DistroAPI['commonDir'] = ConfigManager.getCommonDirectory()
DistroAPI['instanceDir'] = ConfigManager.getInstanceDirectory()
2019-04-08 03:33:40 +00:00
// Load Strings
LangLoader.setupLanguage()
2019-04-08 03:33:40 +00:00
/**
*
* @param {HeliosDistribution} data
*/
function onDistroLoad(data){
if(data != null){
// Resolve the selected server if its value has yet to be set.
if(ConfigManager.getSelectedServer() == null || data.getServerById(ConfigManager.getSelectedServer()) == null){
2022-12-25 03:17:30 +00:00
logger.info('Determining default selected server..')
ConfigManager.setSelectedServer(data.getMainServer().rawServer.id)
ConfigManager.save()
}
}
ipcRenderer.send('distributionIndexDone', data != null)
}
// Ensure Distribution is downloaded and cached.
DistroAPI.getDistribution()
.then(heliosDistro => {
logger.info('Loaded distribution index.')
onDistroLoad(heliosDistro)
})
.catch(err => {
2022-12-25 03:17:30 +00:00
logger.info('Failed to load an older version of the distribution index.')
logger.info('Application cannot run.')
logger.error(err)
onDistroLoad(null)
})
2018-04-15 04:49:20 +00:00
// Clean up temp dir incase previous launches ended unexpectedly.
fs.remove(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
if(err){
logger.warn('Error while cleaning natives directory', err)
} else {
2022-12-25 03:17:30 +00:00
logger.info('Cleaned natives directory.')
}
})