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