Fixes related to offline startup.

Fixed incorrect function name for local distro index loading.
Fixed mojang tooltip not showing statuses when offline.
Added timeout of 2500ms to news loading, remote distro index retrieval, and mojang status loading.
Updates async to fix lodash vulnerability.
This commit is contained in:
Daniel Scalzi 2018-05-22 08:41:22 -04:00
parent ba916aa953
commit a67dac23cf
No known key found for this signature in database
GPG Key ID: 5CA2F145B63535F9
6 changed files with 79 additions and 56 deletions

View File

@ -382,8 +382,12 @@ class AssetGuard extends EventEmitter {
static refreshDistributionDataRemote(launcherPath){
return new Promise((resolve, reject) => {
const distroURL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/westeroscraft.json'
const opts = {
url: distroURL,
timeout: 2500
}
const distroDest = path.join(launcherPath, 'westeroscraft.json')
request(distroURL, (error, resp, body) => {
request(opts, (error, resp, body) => {
if(!error){
distributionData = JSON.parse(body)

View File

@ -89,14 +89,19 @@ exports.status = function(){
return new Promise((resolve, reject) => {
request.get('https://status.mojang.com/check',
{
json: true
json: true,
timeout: 2500
},
function(error, response, body){
if(error || response.statusCode !== 200){
console.warn('Unable to retrieve Mojang status.')
console.debug('Error while retrieving Mojang statuses:', error)
reject(error || response.statusCode)
//reject(error || response.statusCode)
for(let i=0; i<statuses.length; i++){
statuses[i].status = 'grey'
}
resolve(statuses)
} else {
for(let i=0; i<body.length; i++){
const key = Object.keys(body[i])[0]

View File

@ -35,7 +35,7 @@ AssetGuard.refreshDistributionDataRemote(ConfigManager.getLauncherDirectory()).t
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Attempting to load an older version of the distribution index.')
// Try getting a local copy, better than nothing.
AssetGuard.refreshDistributionDateLocal(ConfigManager.getLauncherDirectory()).then((data) => {
AssetGuard.refreshDistributionDataLocal(ConfigManager.getLauncherDirectory()).then((data) => {
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Successfully loaded an older version of the distribution index.')
onDistroLoad(data)

View File

@ -149,6 +149,7 @@ const refreshMojangStatuses = async function(){
try {
const statuses = await Mojang.status()
greenCount = 0
greyCount = 0
for(let i=0; i<statuses.length; i++){
const service = statuses[i]
@ -167,18 +168,24 @@ const refreshMojangStatuses = async function(){
if(service.status === 'yellow' && status !== 'red'){
status = 'yellow'
continue
} else if(service.status === 'red'){
status = 'red'
break
} else {
if(service.status === 'grey'){
++greyCount
}
++greenCount
}
if(greenCount == statuses.length){
}
if(greenCount === statuses.length){
if(greyCount === statuses.length){
status = 'grey'
} else {
status = 'green'
}
}
} catch (err) {
console.warn('Unable to refresh Mojang service status.')
@ -915,7 +922,10 @@ function loadNews(){
const distroData = AssetGuard.getDistributionData()
const newsFeed = distroData['news_feed']
const newsHost = new URL(newsFeed).origin + '/'
$.get(newsFeed, (data) => {
$.ajax(
{
url: newsFeed,
success: (data) => {
const items = $(data).find('item')
const articles = []
@ -958,8 +968,12 @@ function loadNews(){
resolve({
articles
})
},
timeout: 2500
}).catch(err => {
reject(err)
resolve({
articles: null
})
})
})
}

14
package-lock.json generated
View File

@ -178,11 +178,11 @@
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
},
"async": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.0.tgz",
"integrity": "sha512-xAfGg1/NTLBBKlHFmnd7PlmUW9KhVQIUuSrYem9xzFUZy13ScvtyGGejaae9iAVRiRq9+Cx7DPFaAAhCpyxyPw==",
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz",
"integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==",
"requires": {
"lodash": "^4.14.0"
"lodash": "^4.17.10"
}
},
"async-exit-hook": {
@ -1755,9 +1755,9 @@
}
},
"lodash": {
"version": "4.17.4",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
},
"lodash.isequal": {
"version": "4.5.0",

View File

@ -29,7 +29,7 @@
"homepage": "http://www.westeroscraft.com/",
"dependencies": {
"adm-zip": "^0.4.11",
"async": "^2.6.0",
"async": "^2.6.1",
"discord-rpc": "^3.0.0-beta.10",
"ejs": "^2.6.1",
"ejs-electron": "^2.0.3",