Compare commits

...

3 Commits

Author SHA1 Message Date
Kamesuta
3e060693f9
Merge db3a4998d9 into 7e95771957 2023-11-12 13:12:30 +01:00
Daniel Scalzi
7e95771957
Remove dependence on node crypto module in landing.js 2023-11-11 23:37:59 -05:00
Kamesuta
ab7e3c301c
Fix js.uicore.autoUpdate name in en_US.toml (#307) 2023-10-14 16:37:03 -04:00
2 changed files with 79 additions and 84 deletions

View File

@ -2,8 +2,6 @@
* Script for landing.ejs
*/
// Requirements
const cp = require('child_process')
const crypto = require('crypto')
const { URL } = require('url')
const {
MojangRestAPI,
@ -800,6 +798,16 @@ function showNewsAlert(){
$(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
* the UI accordingly.
@ -807,13 +815,11 @@ function showNewsAlert(){
* @returns {Promise.<void>} A promise which resolves when the news
* content has finished loading and transitioning.
*/
function initNews(){
async function initNews(){
return new Promise((resolve, reject) => {
setNewsLoading(true)
let news = {}
loadNews().then(news => {
const news = await loadNews()
newsArr = news?.articles || null
@ -821,11 +827,9 @@ function initNews(){
// News Loading Failed
setNewsLoading(false)
$('#newsErrorLoading').fadeOut(250, () => {
$('#newsErrorFailed').fadeIn(250, () => {
resolve()
})
})
await $('#newsErrorLoading').fadeOut(250).promise()
await $('#newsErrorFailed').fadeIn(250).promise()
} else if(newsArr.length === 0) {
// No News Articles
setNewsLoading(false)
@ -837,18 +841,15 @@ function initNews(){
})
ConfigManager.save()
$('#newsErrorLoading').fadeOut(250, () => {
$('#newsErrorNone').fadeIn(250, () => {
resolve()
})
})
await $('#newsErrorLoading').fadeOut(250).promise()
await $('#newsErrorNone').fadeIn(250).promise()
} else {
// Success
setNewsLoading(false)
const lN = newsArr[0]
const cached = ConfigManager.getNewsCache()
let newHash = crypto.createHash('sha1').update(lN.content).digest('hex')
let newHash = await digestMessage(lN.content)
let newDate = new Date(lN.date)
let isNew = false
@ -895,18 +896,12 @@ function initNews(){
document.getElementById('newsNavigateRight').onclick = () => { switchHandler(true) }
document.getElementById('newsNavigateLeft').onclick = () => { switchHandler(false) }
$('#newsErrorContainer').fadeOut(250, () => {
await $('#newsErrorContainer').fadeOut(250).promise()
displayArticle(newsArr[0], 1)
$('#newsContent').fadeIn(250, () => {
resolve()
})
})
await $('#newsContent').fadeIn(250).promise()
}
})
})
}
/**

View File

@ -275,7 +275,7 @@ failedMessageSelectAnotherAccount = "We were unable to refresh the login for <st
loginButton = "Login"
selectAnotherAccountButton = "Select Another Account"
[uicore.autoUpdate]
[js.uicore.autoUpdate]
checkingForUpdateButton = "Checking for Updates..."
installNowButton = "Install Now"
checkForUpdatesButton = "Check for Updates"