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')
|
2017-12-02 07:59:25 +00:00
|
|
|
|
2022-12-25 03:17:30 +00:00
|
|
|
const ConfigManager = require('./configmanager')
|
|
|
|
const DistroManager = require('./distromanager')
|
|
|
|
const LangLoader = require('./langloader')
|
|
|
|
const { LoggerUtil } = require('helios-core')
|
2018-07-22 15:40:15 +00:00
|
|
|
|
2022-12-25 03:17:30 +00:00
|
|
|
const logger = LoggerUtil.getLogger('Preloader')
|
|
|
|
|
|
|
|
logger.info('Loading..')
|
2017-12-02 07:59:25 +00:00
|
|
|
|
2017-12-03 05:38:22 +00:00
|
|
|
// Load ConfigManager
|
|
|
|
ConfigManager.load()
|
2017-12-03 03:41:47 +00:00
|
|
|
|
2019-04-08 03:33:40 +00:00
|
|
|
// Load Strings
|
|
|
|
LangLoader.loadLanguage('en_US')
|
|
|
|
|
2018-05-08 10:34:16 +00:00
|
|
|
function onDistroLoad(data){
|
|
|
|
if(data != null){
|
|
|
|
|
2018-07-22 17:31:15 +00:00
|
|
|
// Resolve the selected server if its value has yet to be set.
|
2018-07-22 15:40:15 +00:00
|
|
|
if(ConfigManager.getSelectedServer() == null || data.getServer(ConfigManager.getSelectedServer()) == null){
|
2022-12-25 03:17:30 +00:00
|
|
|
logger.info('Determining default selected server..')
|
2018-07-22 15:40:15 +00:00
|
|
|
ConfigManager.setSelectedServer(data.getMainServer().getID())
|
2018-05-08 10:34:16 +00:00
|
|
|
ConfigManager.save()
|
|
|
|
}
|
|
|
|
}
|
2018-07-22 15:40:15 +00:00
|
|
|
ipcRenderer.send('distributionIndexDone', data != null)
|
2018-05-08 10:34:16 +00:00
|
|
|
}
|
|
|
|
|
2017-12-03 05:38:22 +00:00
|
|
|
// Ensure Distribution is downloaded and cached.
|
2018-07-22 15:40:15 +00:00
|
|
|
DistroManager.pullRemote().then((data) => {
|
2022-12-25 03:17:30 +00:00
|
|
|
logger.info('Loaded distribution index.')
|
2017-12-03 03:41:47 +00:00
|
|
|
|
2018-07-22 17:31:15 +00:00
|
|
|
onDistroLoad(data)
|
2018-05-07 05:34:57 +00:00
|
|
|
|
2018-05-08 10:34:16 +00:00
|
|
|
}).catch((err) => {
|
2022-12-25 03:17:30 +00:00
|
|
|
logger.info('Failed to load distribution index.')
|
2018-08-22 18:21:49 +00:00
|
|
|
logger.error(err)
|
2018-05-08 10:34:16 +00:00
|
|
|
|
2022-12-25 03:17:30 +00:00
|
|
|
logger.info('Attempting to load an older version of the distribution index.')
|
2018-05-08 10:34:16 +00:00
|
|
|
// Try getting a local copy, better than nothing.
|
2018-07-22 15:40:15 +00:00
|
|
|
DistroManager.pullLocal().then((data) => {
|
2022-12-25 03:17:30 +00:00
|
|
|
logger.info('Successfully loaded an older version of the distribution index.')
|
2018-05-08 10:34:16 +00:00
|
|
|
|
|
|
|
onDistroLoad(data)
|
|
|
|
|
|
|
|
|
|
|
|
}).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.')
|
2018-08-22 18:21:49 +00:00
|
|
|
logger.error(err)
|
2018-05-08 10:34:16 +00:00
|
|
|
|
|
|
|
onDistroLoad(null)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2018-05-07 05:34:57 +00:00
|
|
|
})
|
2018-04-15 04:00:08 +00:00
|
|
|
|
2018-04-15 04:49:20 +00:00
|
|
|
// Clean up temp dir incase previous launches ended unexpectedly.
|
2018-12-01 13:20:42 +00:00
|
|
|
fs.remove(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
|
2018-04-15 04:00:08 +00:00
|
|
|
if(err){
|
2018-08-22 18:21:49 +00:00
|
|
|
logger.warn('Error while cleaning natives directory', err)
|
2018-04-15 04:00:08 +00:00
|
|
|
} else {
|
2022-12-25 03:17:30 +00:00
|
|
|
logger.info('Cleaned natives directory.')
|
2018-04-15 04:00:08 +00:00
|
|
|
}
|
|
|
|
})
|