HeliosLauncher/app/assets/js/assetexec.js
Daniel Scalzi 7dcce68455
Updated Distribution Index spec and impl.
Added distromanager.js to represent distro elements.
Moved all distro refresh code to distromanager.js.
Overhauled assetexec.js.
Overhauled handling of assetexec.js output in landing.js.
Overhauled events emitted by assetguard.js.
Improved doenload processing in assetguard.
Updated discord-rpc to v3.0.0.
Replaced westeroscraft.json with distribution.json.
Use npm in travis for windows + linux.
Remove file extension from imports.
Added liteloader + macromod + shaders to distribution.json.
2018-07-22 11:40:15 -04:00

46 lines
1.5 KiB
JavaScript

const { AssetGuard } = require('./assetguard')
const tracker = new AssetGuard(process.argv[2], process.argv[3])
console.log('AssetExec Started')
// Temporary for debug purposes.
process.on('unhandledRejection', r => console.log(r))
tracker.on('validate', (data) => {
process.send({context: 'validate', data})
})
tracker.on('progress', (data, acc, total) => {
process.send({context: 'progress', data, value: acc, total, percent: parseInt((acc/total)*100)})
})
tracker.on('complete', (data, ...args) => {
process.send({context: 'complete', data, args})
})
tracker.on('error', (data, error) => {
process.send({context: 'error', data, error})
})
process.on('message', (msg) => {
if(msg.task === 'execute'){
const func = msg.function
let nS = tracker[func]
let iS = AssetGuard[func]
if(typeof nS === 'function' || typeof iS === 'function'){
const f = typeof nS === 'function' ? nS : iS
const res = f.apply(f === nS ? tracker : null, msg.argsArr)
if(res instanceof Promise){
res.then((v) => {
process.send({result: v, context: func})
}).catch((err) => {
process.send({result: err, context: func})
})
} else {
process.send({result: res, context: func})
}
}
}
})
process.on('disconnect', () => {
console.log('AssetExec Disconnected')
process.exit(0)
})