Skip to content

Commit

Permalink
Added indication for when there is new news.
Browse files Browse the repository at this point in the history
  • Loading branch information
dscalzi committed Jun 5, 2018
1 parent 05fe516 commit 08eb047
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 18 deletions.
11 changes: 11 additions & 0 deletions app/assets/css/launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,17 @@ input:checked + .toggleSwitchSlider:before {
stroke: rgba(255, 255, 255, 0.75);
}

/* Icon which indicates there is new news. */
#newsButtonAlert {
width: 5px;
height: 5px;
position: absolute;
border-radius: 50%;
background: red;
right: -1px;
top: 50%;
}

/* Arrow image which floats above the news button. */
#newsButtonSVG {
height: 11px;
Expand Down
24 changes: 12 additions & 12 deletions app/assets/js/assetguard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
* @module assetguard
*/
// Requirements
const AdmZip = require('adm-zip')
const async = require('async')
const AdmZip = require('adm-zip')
const async = require('async')
const child_process = require('child_process')
const crypto = require('crypto')
const EventEmitter = require('events')
const fs = require('fs')
const isDev = require('electron-is-dev')
const mkpath = require('mkdirp');
const path = require('path')
const Registry = require('winreg')
const request = require('request')
const tar = require('tar-fs')
const zlib = require('zlib')
const crypto = require('crypto')
const EventEmitter = require('events')
const fs = require('fs')
const isDev = require('electron-is-dev')
const mkpath = require('mkdirp');
const path = require('path')
const Registry = require('winreg')
const request = require('request')
const tar = require('tar-fs')
const zlib = require('zlib')

// Constants
const PLATFORM_MAP = {
Expand Down
43 changes: 41 additions & 2 deletions app/assets/js/configmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const DEFAULT_CONFIG = {
allowPrerelease: false
}
},
newsCache: {
date: null,
content: null,
dismissed: false
},
commonDirectory: path.join(dataPath, 'common'),
instanceDirectory: path.join(dataPath, 'instances'),
clientToken: uuidV4().replace(/-/g, ''),
Expand Down Expand Up @@ -143,9 +148,39 @@ exports.getTempNativeFolder = function(){

// System Settings (Unconfigurable on UI)

/**
* Retrieve the news cache to determine
* whether or not there is newer news.
*
* @returns {Object} The news cache object.
*/
exports.getNewsCache = function(){
return config.newsCache
}

/**
* Set the new news cache object.
*
* @param {Object} newsCache The new news cache object.
*/
exports.setNewsCache = function(newsCache){
config.newsCache = newsCache
}

/**
* Set whether or not the news has been dismissed (checked)
*
* @param {boolean} dismissed Whether or not the news has been dismissed (checked).
*/
exports.setNewsCacheDismissed = function(dismissed){
config.newsCache.dismissed = dismissed
}

/**
* Retrieve the common directory for shared
* game files (assets, libraries, etc).
*
* @returns {string} The launcher's common directory.
*/
exports.getCommonDirectory = function(){
return config.commonDirectory
Expand All @@ -154,6 +189,8 @@ exports.getCommonDirectory = function(){
/**
* Retrieve the instance directory for the per
* server game directories.
*
* @returns {string} The launcher's instance directory.
*/
exports.getInstanceDirectory = function(){
return config.instanceDirectory
Expand Down Expand Up @@ -419,7 +456,8 @@ exports.setGameWidth = function(resWidth){
/**
* Validate a potential new width value.
*
* @param {*} resWidth The width value to validate.
* @param {number} resWidth The width value to validate.
* @returns {boolean} Whether or not the value is valid.
*/
exports.validateGameWidth = function(resWidth){
const nVal = Number.parseInt(resWidth)
Expand Down Expand Up @@ -448,7 +486,8 @@ exports.setGameHeight = function(resHeight){
/**
* Validate a potential new height value.
*
* @param {*} resHeight The height value to validate.
* @param {number} resHeight The height value to validate.
* @returns {boolean} Whether or not the value is valid.
*/
exports.validateGameHeight = function(resHeight){
const nVal = Number.parseInt(resHeight)
Expand Down
72 changes: 68 additions & 4 deletions app/assets/js/scripts/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
// Requirements
const cp = require('child_process')
const crypto = require('crypto')
const {URL} = require('url')

// Internal Requirements
Expand Down Expand Up @@ -774,11 +775,17 @@ function slide_(up){
document.getElementById('newsButton').onclick = () => {
// Toggle tabbing.
if(newsActive){
$("#landingContainer *").removeAttr('tabindex')
$("#newsContainer *").attr('tabindex', '-1')
$('#landingContainer *').removeAttr('tabindex')
$('#newsContainer *').attr('tabindex', '-1')
} else {
$("#landingContainer *").attr('tabindex', '-1')
$("#newsContainer, #newsContainer *, #lower, #lower #center *").removeAttr('tabindex')
$('#landingContainer *').attr('tabindex', '-1')
$('#newsContainer, #newsContainer *, #lower, #lower #center *').removeAttr('tabindex')
if(newsAlertShown){
$('#newsButtonAlert').fadeOut(2000)
newsAlertShown = false
ConfigManager.setNewsCacheDismissed(true)
ConfigManager.save()
}
}
slide_(!newsActive)
newsActive = !newsActive
Expand Down Expand Up @@ -841,6 +848,16 @@ function reloadNews(){
})
}

let newsAlertShown = false

/**
* Show the news alert indicating there is new news.
*/
function showNewsAlert(){
newsAlertShown = true
$(newsButtonAlert).fadeIn(250)
}

/**
* Initialize News UI. This will load the news and prepare
* the UI accordingly.
Expand Down Expand Up @@ -871,6 +888,13 @@ function initNews(){
// No News Articles
setNewsLoading(false)

ConfigManager.setNewsCache({
date: null,
content: null,
dismissed: false
})
ConfigManager.save()

$('#newsErrorLoading').fadeOut(250, () => {
$('#newsErrorNone').fadeIn(250, () => {
resolve()
Expand All @@ -880,6 +904,46 @@ function initNews(){
// Success
setNewsLoading(false)

const lN = newsArr[0]
const cached = ConfigManager.getNewsCache()
let newHash = crypto.createHash('sha1').update(lN.content).digest('hex')
let newDate = new Date(lN.date)
let isNew = false

if(cached.date != null && cached.content != null){

if(new Date(cached.date) >= newDate){

// Compare Content
if(cached.content !== newHash){
isNew = true
showNewsAlert()
} else {
if(!cached.dismissed){
isNew = true
showNewsAlert()
}
}

} else {
isNew = true
showNewsAlert()
}

} 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)
Expand Down
1 change: 1 addition & 0 deletions app/landing.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<div id="content">
<button id="newsButton">
<!--<img src="assets/images/icons/arrow.svg" id="newsButtonSVG"/>-->
<div id="newsButtonAlert" style="display: none;"></div>
<svg id="newsButtonSVG" viewBox="0 0 24.87 13.97">
<defs>
<style>.arrowLine{fill:none;stroke:#FFF;stroke-width:2px;}</style>
Expand Down

0 comments on commit 08eb047

Please sign in to comment.