mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 19:52:14 -08:00
Compare commits
1 Commits
09f924093e
...
2998140f89
Author | SHA1 | Date | |
---|---|---|---|
|
2998140f89 |
@ -2,6 +2,8 @@
|
|||||||
* Script for landing.ejs
|
* Script for landing.ejs
|
||||||
*/
|
*/
|
||||||
// Requirements
|
// Requirements
|
||||||
|
const cp = require('child_process')
|
||||||
|
const crypto = require('crypto')
|
||||||
const { URL } = require('url')
|
const { URL } = require('url')
|
||||||
const {
|
const {
|
||||||
MojangRestAPI,
|
MojangRestAPI,
|
||||||
@ -798,16 +800,6 @@ function showNewsAlert(){
|
|||||||
$(newsButtonAlert).fadeIn(250)
|
$(newsButtonAlert).fadeIn(250)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function digestMessage(str) {
|
|
||||||
const msgUint8 = new TextEncoder().encode(str)
|
|
||||||
const hashBuffer = await crypto.subtle.digest('SHA-1', msgUint8)
|
|
||||||
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
||||||
const hashHex = hashArray
|
|
||||||
.map((b) => b.toString(16).padStart(2, '0'))
|
|
||||||
.join('')
|
|
||||||
return hashHex
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize News UI. This will load the news and prepare
|
* Initialize News UI. This will load the news and prepare
|
||||||
* the UI accordingly.
|
* the UI accordingly.
|
||||||
@ -815,11 +807,13 @@ async function digestMessage(str) {
|
|||||||
* @returns {Promise.<void>} A promise which resolves when the news
|
* @returns {Promise.<void>} A promise which resolves when the news
|
||||||
* content has finished loading and transitioning.
|
* content has finished loading and transitioning.
|
||||||
*/
|
*/
|
||||||
async function initNews(){
|
function initNews(){
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
setNewsLoading(true)
|
setNewsLoading(true)
|
||||||
|
|
||||||
const news = await loadNews()
|
let news = {}
|
||||||
|
loadNews().then(news => {
|
||||||
|
|
||||||
newsArr = news?.articles || null
|
newsArr = news?.articles || null
|
||||||
|
|
||||||
@ -827,9 +821,11 @@ async function initNews(){
|
|||||||
// News Loading Failed
|
// News Loading Failed
|
||||||
setNewsLoading(false)
|
setNewsLoading(false)
|
||||||
|
|
||||||
await $('#newsErrorLoading').fadeOut(250).promise()
|
$('#newsErrorLoading').fadeOut(250, () => {
|
||||||
await $('#newsErrorFailed').fadeIn(250).promise()
|
$('#newsErrorFailed').fadeIn(250, () => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
} else if(newsArr.length === 0) {
|
} else if(newsArr.length === 0) {
|
||||||
// No News Articles
|
// No News Articles
|
||||||
setNewsLoading(false)
|
setNewsLoading(false)
|
||||||
@ -841,15 +837,18 @@ async function initNews(){
|
|||||||
})
|
})
|
||||||
ConfigManager.save()
|
ConfigManager.save()
|
||||||
|
|
||||||
await $('#newsErrorLoading').fadeOut(250).promise()
|
$('#newsErrorLoading').fadeOut(250, () => {
|
||||||
await $('#newsErrorNone').fadeIn(250).promise()
|
$('#newsErrorNone').fadeIn(250, () => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// Success
|
// Success
|
||||||
setNewsLoading(false)
|
setNewsLoading(false)
|
||||||
|
|
||||||
const lN = newsArr[0]
|
const lN = newsArr[0]
|
||||||
const cached = ConfigManager.getNewsCache()
|
const cached = ConfigManager.getNewsCache()
|
||||||
let newHash = await digestMessage(lN.content)
|
let newHash = crypto.createHash('sha1').update(lN.content).digest('hex')
|
||||||
let newDate = new Date(lN.date)
|
let newDate = new Date(lN.date)
|
||||||
let isNew = false
|
let isNew = false
|
||||||
|
|
||||||
@ -896,12 +895,18 @@ async function initNews(){
|
|||||||
|
|
||||||
document.getElementById('newsNavigateRight').onclick = () => { switchHandler(true) }
|
document.getElementById('newsNavigateRight').onclick = () => { switchHandler(true) }
|
||||||
document.getElementById('newsNavigateLeft').onclick = () => { switchHandler(false) }
|
document.getElementById('newsNavigateLeft').onclick = () => { switchHandler(false) }
|
||||||
await $('#newsErrorContainer').fadeOut(250).promise()
|
|
||||||
|
$('#newsErrorContainer').fadeOut(250, () => {
|
||||||
displayArticle(newsArr[0], 1)
|
displayArticle(newsArr[0], 1)
|
||||||
await $('#newsContent').fadeIn(250).promise()
|
$('#newsContent').fadeIn(250, () => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user