mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 11:42:14 -08:00
Compare commits
4 Commits
2998140f89
...
09f924093e
Author | SHA1 | Date | |
---|---|---|---|
|
09f924093e | ||
|
7e95771957 | ||
|
f551a064ce | ||
|
84c34e84ab |
@ -2,8 +2,6 @@
|
|||||||
* 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,
|
||||||
@ -800,6 +798,16 @@ 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.
|
||||||
@ -807,106 +815,93 @@ function showNewsAlert(){
|
|||||||
* @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.
|
||||||
*/
|
*/
|
||||||
function initNews(){
|
async function initNews(){
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
setNewsLoading(true)
|
||||||
setNewsLoading(true)
|
|
||||||
|
|
||||||
let news = {}
|
const news = await loadNews()
|
||||||
loadNews().then(news => {
|
|
||||||
|
|
||||||
newsArr = news?.articles || null
|
newsArr = news?.articles || null
|
||||||
|
|
||||||
if(newsArr == null){
|
if(newsArr == null){
|
||||||
// News Loading Failed
|
// News Loading Failed
|
||||||
setNewsLoading(false)
|
setNewsLoading(false)
|
||||||
|
|
||||||
$('#newsErrorLoading').fadeOut(250, () => {
|
await $('#newsErrorLoading').fadeOut(250).promise()
|
||||||
$('#newsErrorFailed').fadeIn(250, () => {
|
await $('#newsErrorFailed').fadeIn(250).promise()
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else if(newsArr.length === 0) {
|
|
||||||
// No News Articles
|
|
||||||
setNewsLoading(false)
|
|
||||||
|
|
||||||
ConfigManager.setNewsCache({
|
} else if(newsArr.length === 0) {
|
||||||
date: null,
|
// No News Articles
|
||||||
content: null,
|
setNewsLoading(false)
|
||||||
dismissed: false
|
|
||||||
})
|
|
||||||
ConfigManager.save()
|
|
||||||
|
|
||||||
$('#newsErrorLoading').fadeOut(250, () => {
|
ConfigManager.setNewsCache({
|
||||||
$('#newsErrorNone').fadeIn(250, () => {
|
date: null,
|
||||||
resolve()
|
content: null,
|
||||||
})
|
dismissed: false
|
||||||
})
|
})
|
||||||
} else {
|
ConfigManager.save()
|
||||||
// Success
|
|
||||||
setNewsLoading(false)
|
|
||||||
|
|
||||||
const lN = newsArr[0]
|
await $('#newsErrorLoading').fadeOut(250).promise()
|
||||||
const cached = ConfigManager.getNewsCache()
|
await $('#newsErrorNone').fadeIn(250).promise()
|
||||||
let newHash = crypto.createHash('sha1').update(lN.content).digest('hex')
|
} else {
|
||||||
let newDate = new Date(lN.date)
|
// Success
|
||||||
let isNew = false
|
setNewsLoading(false)
|
||||||
|
|
||||||
if(cached.date != null && cached.content != null){
|
const lN = newsArr[0]
|
||||||
|
const cached = ConfigManager.getNewsCache()
|
||||||
|
let newHash = await digestMessage(lN.content)
|
||||||
|
let newDate = new Date(lN.date)
|
||||||
|
let isNew = false
|
||||||
|
|
||||||
if(new Date(cached.date) >= newDate){
|
if(cached.date != null && cached.content != null){
|
||||||
|
|
||||||
// Compare Content
|
if(new Date(cached.date) >= newDate){
|
||||||
if(cached.content !== newHash){
|
|
||||||
isNew = true
|
|
||||||
showNewsAlert()
|
|
||||||
} else {
|
|
||||||
if(!cached.dismissed){
|
|
||||||
isNew = true
|
|
||||||
showNewsAlert()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
// Compare Content
|
||||||
|
if(cached.content !== newHash){
|
||||||
|
isNew = true
|
||||||
|
showNewsAlert()
|
||||||
|
} else {
|
||||||
|
if(!cached.dismissed){
|
||||||
isNew = true
|
isNew = true
|
||||||
showNewsAlert()
|
showNewsAlert()
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
isNew = true
|
|
||||||
showNewsAlert()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isNew){
|
} else {
|
||||||
ConfigManager.setNewsCache({
|
isNew = true
|
||||||
date: newDate.getTime(),
|
showNewsAlert()
|
||||||
content: newHash,
|
|
||||||
dismissed: false
|
|
||||||
})
|
|
||||||
ConfigManager.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
const switchHandler = (forward) => {
|
|
||||||
let cArt = parseInt(newsContent.getAttribute('article'))
|
|
||||||
let nxtArt = forward ? (cArt >= newsArr.length-1 ? 0 : cArt + 1) : (cArt <= 0 ? newsArr.length-1 : cArt - 1)
|
|
||||||
|
|
||||||
displayArticle(newsArr[nxtArt], nxtArt+1)
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('newsNavigateRight').onclick = () => { switchHandler(true) }
|
|
||||||
document.getElementById('newsNavigateLeft').onclick = () => { switchHandler(false) }
|
|
||||||
|
|
||||||
$('#newsErrorContainer').fadeOut(250, () => {
|
|
||||||
displayArticle(newsArr[0], 1)
|
|
||||||
$('#newsContent').fadeIn(250, () => {
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
} else {
|
||||||
|
isNew = true
|
||||||
})
|
showNewsAlert()
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isNew){
|
||||||
|
ConfigManager.setNewsCache({
|
||||||
|
date: newDate.getTime(),
|
||||||
|
content: newHash,
|
||||||
|
dismissed: false
|
||||||
|
})
|
||||||
|
ConfigManager.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
const switchHandler = (forward) => {
|
||||||
|
let cArt = parseInt(newsContent.getAttribute('article'))
|
||||||
|
let nxtArt = forward ? (cArt >= newsArr.length-1 ? 0 : cArt + 1) : (cArt <= 0 ? newsArr.length-1 : cArt - 1)
|
||||||
|
|
||||||
|
displayArticle(newsArr[nxtArt], nxtArt+1)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('newsNavigateRight').onclick = () => { switchHandler(true) }
|
||||||
|
document.getElementById('newsNavigateLeft').onclick = () => { switchHandler(false) }
|
||||||
|
await $('#newsErrorContainer').fadeOut(250).promise()
|
||||||
|
displayArticle(newsArr[0], 1)
|
||||||
|
await $('#newsContent').fadeIn(250).promise()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,7 @@ if(!isDev){
|
|||||||
loggerAutoUpdater.info('New update available', info.version)
|
loggerAutoUpdater.info('New update available', info.version)
|
||||||
|
|
||||||
if(process.platform === 'darwin'){
|
if(process.platform === 'darwin'){
|
||||||
info.darwindownload = `https://github.com/dscalzi/HeliosLauncher/releases/download/v${info.version}/Helios-Launcher-setup-${info.version}${process.arch === 'arm64' ? '-arm64' : '-x64'}.dmg`
|
info.darwindownload = `https://github.com/dscalzi/HeliosLauncher/releases/download/v${info.version}/Helios-Launcher-setup.dmg`
|
||||||
showUpdateUI(info)
|
showUpdateUI(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,4 +211,4 @@ document.addEventListener('keydown', function (e) {
|
|||||||
let window = remote.getCurrentWindow()
|
let window = remote.getCurrentWindow()
|
||||||
window.toggleDevTools()
|
window.toggleDevTools()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -31,9 +31,8 @@ mac:
|
|||||||
target:
|
target:
|
||||||
- target: 'dmg'
|
- target: 'dmg'
|
||||||
arch:
|
arch:
|
||||||
- 'x64'
|
- 'universal'
|
||||||
- 'arm64'
|
artifactName: '${productName}-setup-${version}.${ext}'
|
||||||
artifactName: '${productName}-setup-${version}-${arch}.${ext}'
|
|
||||||
category: 'public.app-category.games'
|
category: 'public.app-category.games'
|
||||||
|
|
||||||
# Linux Configuration
|
# Linux Configuration
|
||||||
@ -48,4 +47,4 @@ linux:
|
|||||||
|
|
||||||
directories:
|
directories:
|
||||||
buildResources: 'build'
|
buildResources: 'build'
|
||||||
output: 'dist'
|
output: 'dist'
|
||||||
|
Loading…
Reference in New Issue
Block a user