Improving application startup flow.

Major improvements to distribution index loading.
Implemented new transitional UI for startup.
If **no** distribution index is loaded on startup, completion of startup will be prevented and the user will be shown a message displaying the issue.
Launch errors are now shown as overlays.
Many more minor fixes and enhancements.
This commit is contained in:
Daniel Scalzi 2018-05-08 06:34:16 -04:00
parent cd4f7918c8
commit f161e196be
No known key found for this signature in database
GPG Key ID: 5CA2F145B63535F9
9 changed files with 298 additions and 143 deletions

View File

@ -7,10 +7,13 @@
<link type="text/css" rel="stylesheet" href="./assets/css/launcher.css">
<style>
body {
background: url('assets/images/backgrounds/<%=bkid%>.jpg') no-repeat center center fixed;
/*background: url('assets/images/backgrounds/<%=bkid%>.jpg') no-repeat center center fixed;*/
transition: background-image 1s ease;
background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBkZWZhdWx0IHF1YWxpdHkK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAPwBwAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A8VooopDCiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9k=');
background-size: cover;
}
#main {
display: none;
height: calc(100% - 22px);
background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0) 100%);
width: 100%;
@ -22,7 +25,7 @@
}
</style>
</head>
<body>
<body bkid="<%=bkid%>">
<% include frame.ejs %>
<div id="main">
<% include welcome.ejs %>
@ -30,5 +33,13 @@
<% include landing.ejs %>
</div>
<% include overlay.ejs %>
<div id="loadingContainer">
<div id="loadingContent">
<div id="loadSpinnerContainer">
<img id="loadCenterImage" src="assets/images/westeroscraftlogo1.png">
<img id="loadSpinnerImage" class="rotating" src="assets/images/westeroscraftlogo2.png">
</div>
</div>
</div>
</body>
</html>

View File

@ -55,7 +55,8 @@ p {
z-index: 100;
display: flex;
flex-direction: column;
background: rgba(1, 2, 1, 0.5);
transition: background-color 1s ease;
/*background-color: rgba(1, 2, 1, 0.5);*/
-webkit-user-select: none;
}
@ -809,67 +810,6 @@ p {
transform: rotate(45deg);
}
/* * *
* Login View | Loader
* * */
/* Will reuse this elsewhere down the line.
#loginLoading {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.80);
}
#loginLoadingContent {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#loadSpinnerContainer {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
#loadCenterImage {
position: absolute;
width: 200px;
height: auto;
}
#loadSpinnerImage {
width: 280px;
height: auto;
}
#loadDescText {
color: #f1eada;
font-family: 'Avenir Medium';
font-weight: bold;
letter-spacing: 1px;
font-size: 16px;
}
@keyframes rotating {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.rotating {
animation: rotating 10s linear infinite;
}*/
/*
#login_filter {
height: calc(100% - 22px);
@ -2092,3 +2032,65 @@ p {
#serverSelectCancel:active {
color: rgba(165, 165, 165, 0.75);
}
/*******************************************************************************
* *
* Loading Element (app.ejs) *
* *
******************************************************************************/
/* Loading container, placed above everything. */
#loadingContainer {
position: absolute;
z-index: 400;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: calc(100% - 22px);
}
/* Loading content container. */
#loadingContent {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* Spinner container. */
#loadSpinnerContainer {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
/* Stationary image for the spinner. */
#loadCenterImage {
position: absolute;
width: 200px;
height: auto;
}
/* Rotating image for the spinner. */
#loadSpinnerImage {
width: 280px;
height: auto;
}
/* Rotating animation for the spinner. */
@keyframes rotating {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
/* Class which is applied when the spinner image is spinning. */
.rotating {
animation: rotating 10s linear infinite;
}

View File

@ -41,6 +41,8 @@ process.on('message', (msg) => {
if(res instanceof Promise){
res.then((v) => {
process.send({result: v, content: msg.content})
}).catch((err) => {
process.send({result: v, content: msg.content})
})
} else {
process.send({result: res, content: msg.content})

View File

@ -373,21 +373,17 @@ class AssetGuard extends EventEmitter {
// #region
/**
* Statically retrieve the distribution data.
* Retrieve a new copy of the distribution index from our servers.
*
* @param {string} launcherPath The root launcher directory.
* @param {boolean} cached Optional. False if the distro should be freshly downloaded, else
* a cached copy will be returned.
* @returns {Promise.<Object>} A promise which resolves to the distribution data object.
*/
static retrieveDistributionData(launcherPath, cached = true){
static retrieveDistributionDataFresh(launcherPath){
return new Promise((resolve, reject) => {
if(!cached || distributionData == null){
// TODO Download file from upstream.
const distroURL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/westeroscraft.json'
const distroDest = path.join(launcherPath, 'westeroscraft.json')
// TODO Fulfill with JSON.parse()
request(distroURL, (error, resp, body) => {
const distroURL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/westeroscraft.json'
const distroDest = path.join(launcherPath, 'westeroscraft.json')
request(distroURL, (error, resp, body) => {
if(!error){
distributionData = JSON.parse(body)
fs.writeFile(distroDest, body, 'utf-8', (err) => {
@ -397,12 +393,32 @@ class AssetGuard extends EventEmitter {
reject(err)
}
})
} else {
reject(error)
}
})
})
}
/**
* Retrieve a local copy of the distribution index asynchronously.
*
* @param {string} launcherPath The root launcher directory.
* @param {boolean} cached Optional. False if the distro file should be read from the
* disk and re-cached, otherwise a cached copy will be returned.
* @returns {Promise.<Object>} A promise which resolves to the distribution data object.
*/
static retrieveDistributionData(launcherPath, cached = true){
return new Promise((resolve, reject) => {
if(!cached || distributionData == null){
fs.readFile(path.join(launcherPath, 'westeroscraft.json'), 'utf-8', (err, data) => {
if(!err){
distributionData = JSON.parse(data)
resolve(distributionData)
} else {
reject(err)
}
})
// Workaround while file is not hosted.
/*fs.readFile(path.join(__dirname, '..', 'westeroscraft.json'), 'utf-8', (err, data) => {
distributionData = JSON.parse(data)
resolve(distributionData)
})*/
} else {
resolve(distributionData)
}
@ -410,11 +426,11 @@ class AssetGuard extends EventEmitter {
}
/**
* Recieved a cached version of the distribution index.
* Retrieve a local copy of the distribution index synchronously.
*
* @param {string} launcherPath The root launcher directory.
* @param {boolean} cached Optional. False if the distro should be freshly downloaded, else
* a cached copy will be returned.
* @param {boolean} cached Optional. False if the distro file should be read from the
* disk and re-cached, otherwise a cached copy will be returned.
* @returns {Object} The distribution data object.
*/
static retrieveDistributionDataSync(launcherPath, cached = true){
@ -453,7 +469,7 @@ class AssetGuard extends EventEmitter {
*/
static getServerById(launcherPath, serverID){
if(distributionData == null){
AssetGuard.retrieveDistributionDataSync(launcherPath, false)
AssetGuard.retrieveDistributionDataSync(launcherPath, true)
}
const servers = distributionData.servers
let serv = null
@ -1285,15 +1301,8 @@ class AssetGuard extends EventEmitter {
validateDistribution(serverpackid){
const self = this
return new Promise((resolve, reject) => {
AssetGuard.retrieveDistributionData(self.launcherPath, false).then((value) => {
/*const servers = value.servers
let serv = null
for(let i=0; i<servers.length; i++){
if(servers[i].id === serverpackid){
serv = servers[i]
break
}
}*/
const cbFunc = function(){
const serv = AssetGuard.getServerById(self.launcherPath, serverpackid)
if(serv == null) {
@ -1310,6 +1319,32 @@ class AssetGuard extends EventEmitter {
}
}
resolve(serv)
}
AssetGuard.retrieveDistributionDataFresh(self.launcherPath).then((value) => {
console.log('Loaded fresh copy of the distribution index.')
cbFunc()
}).catch((err) => {
console.log('Failed to load fresh copy of the distribution index.')
console.log('Attempting to load an older copy of the distribution index.')
AssetGuard.retrieveDistributionData(self.launcherPath, false).then((value) => {
console.log('Successfully loaded an older copy of the distribution index.')
cbFunc()
}).catch((err) => {
console.log('Failed to load an older copy of the distribution index. Cannot launch.')
reject(err)
})
})
})
}
@ -1370,7 +1405,7 @@ class AssetGuard extends EventEmitter {
loadForgeData(serverpack){
const self = this
return new Promise(async (resolve, reject) => {
let distro = AssetGuard.retrieveDistributionDataSync(self.launcherPath)
let distro = AssetGuard.retrieveDistributionDataSync(self.launcherPath, true)
const servers = distro.servers
let serv = null

View File

@ -10,22 +10,47 @@ console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Loading..')
// Load ConfigManager
ConfigManager.load()
function onDistroLoad(data){
if(data != null){
// Resolve the selected server if its value has yet to be set.
if(ConfigManager.getSelectedServer() == null || AssetGuard.getServerById(ConfigManager.getLauncherDirectory(), ConfigManager.getSelectedServer()) == null){
console.log('Determining default selected server..')
ConfigManager.setSelectedServer(AssetGuard.resolveSelectedServer(ConfigManager.getLauncherDirectory()).id)
ConfigManager.save()
}
}
ipcRenderer.send('distributionIndexDone', data)
}
// Ensure Distribution is downloaded and cached.
AssetGuard.retrieveDistributionData(ConfigManager.getLauncherDirectory(), false).then((data) => {
AssetGuard.retrieveDistributionDataFresh(ConfigManager.getLauncherDirectory()).then((data) => {
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Loaded distribution index.')
// Resolve the selected server if its value has yet to be set.
if(ConfigManager.getSelectedServer() == null){
console.log('Determining default selected server..')
ConfigManager.setSelectedServer(AssetGuard.resolveSelectedServer(ConfigManager.getLauncherDirectory()).id)
ConfigManager.save()
}
onDistroLoad(data)
ipcRenderer.send('distributionIndexDone', data)
}).catch(err => {
}).catch((err) => {
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Failed to load distribution index.')
console.err(err)
console.error(err)
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.retrieveDistributionData(ConfigManager.getLauncherDirectory(), false).then((data) => {
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Successfully loaded an older version of the distribution index.')
onDistroLoad(data)
}).catch((err) => {
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Failed to load an older version of the distribution index.')
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Application cannot run.')
console.error(err)
onDistroLoad(null)
})
})
// Clean up temp dir incase previous launches ended unexpectedly.

View File

@ -418,13 +418,30 @@ function dlAsync(login = true){
aEx.on('message', (m) => {
if(m.content === 'validateDistribution'){
setLaunchPercentage(20, 100)
serv = m.result
console.log('Forge Validation Complete.')
if(m.result instanceof Error){
// Begin version load.
setLaunchDetails('Loading version information..')
aEx.send({task: 0, content: 'loadVersionData', argsArr: [serv.mc_version]})
setOverlayContent(
'Fatal Error',
'Could not load a copy of the distribution index. See the console for more details.',
'Okay'
)
setOverlayHandler(null)
toggleOverlay(true)
toggleLaunchArea(false)
// Disconnect from AssetExec
aEx.disconnect()
} else {
setLaunchPercentage(20, 100)
serv = m.result
console.log('Forge Validation Complete.')
// Begin version load.
setLaunchDetails('Loading version information..')
aEx.send({task: 0, content: 'loadVersionData', argsArr: [serv.mc_version]})
}
} else if(m.content === 'loadVersionData'){
@ -492,15 +509,29 @@ function dlAsync(login = true){
} else if(m.task === 0.9) {
console.error(m.err)
if(m.err.code === 'ENOENT'){
setLaunchDetails('Download error.. internet?')
setOverlayContent(
'Download Error',
'Could not connect to the file server. Ensure that you are connected to the internet and try again.',
'Okay'
)
setOverlayHandler(null)
} else {
setLaunchDetails('Download error.. try again.')
setOverlayContent(
'Download Error',
'Check the console for more details. Please try again.',
'Okay'
)
setOverlayHandler(null)
}
setTimeout(() => {
toggleLaunchArea(false)
}, 5000)
toggleOverlay(true)
toggleLaunchArea(false)
// Disconnect from AssetExec
aEx.disconnect()
} else if(m.task === 1){
@ -565,7 +596,7 @@ function dlAsync(login = true){
proc.stdout.on('data', gameStateChange)
// Init Discord Hook
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getLauncherDirectory())
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getLauncherDirectory(), true)
if(distro.discord != null && serv.discord != null){
DiscordWrapper.initRPC(distro.discord, serv.discord)
hasRPC = true
@ -579,14 +610,15 @@ function dlAsync(login = true){
} catch(err) {
// Show that there was an error then hide the
// progress area. Maybe switch this to an error
// alert in the future. TODO
setLaunchDetails('Error: See log for details..')
console.log(err)
setTimeout(function(){
toggleLaunchArea(false)
}, 5000)
console.error('Error during launch', err)
setOverlayContent(
'Error During Launch',
'Please check the console for more details.',
'Okay'
)
setOverlayHandler(null)
toggleOverlay(true)
toggleLaunchArea(false)
}
}
@ -842,9 +874,8 @@ function loadNews(){
}).catch(err => {
reject(err)
})
}).catch((err) => {
console.log('Error Loading News', err)
})
})
}
// Load News
initNews()

View File

@ -17,6 +17,7 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
}
if(typeof dismissable === 'string'){
content = dismissable
dismissable = false
}
if(toggleState){
document.getElementById('main').setAttribute('overlay', true)

View File

@ -7,18 +7,63 @@ const path = require('path')
const ConfigManager = require('./assets/js/configmanager.js')
let rscShouldLoad = false
let fatalStartupError = false
function showMainUI(){
updateSelectedServer(AssetGuard.getServerById(ConfigManager.getLauncherDirectory(), ConfigManager.getSelectedServer()).name)
refreshServerStatus()
setTimeout(() => {
document.getElementById('frameBar').style.backgroundColor = 'rgba(1, 2, 1, 0.5)'
document.body.style.backgroundImage = `url('assets/images/backgrounds/${document.body.getAttribute('bkid')}.jpg')`
$('#main').show()
if(ConfigManager.isFirstLaunch()){
$('#welcomeContainer').fadeIn(1000)
} else {
$('#landingContainer').fadeIn(1000)
}
setTimeout(() => {
$('#loadingContainer').fadeOut(750, () => {
$('#loadSpinnerImage').removeClass('rotating')
})
}, 500)
}, 750)
initNews()
}
function showFatalStartupError(){
setTimeout(() => {
$('#loadingContainer').fadeOut(250, () => {
document.getElementById('overlayContainer').style.background = 'none'
setOverlayContent(
'Fatal Error: Unable to Load Distribution Index',
'A connection could not be established to our servers to download the distribution index. No local copies were available to load. <br><br>The distribution index is an essential file which provides the latest server information. The launcher is unable to start without it. Ensure you are connected to the internet and relaunch the application.',
'Close'
)
setOverlayHandler(() => {
const window = remote.getCurrentWindow()
window.close()
})
toggleOverlay(true)
})
}, 750)
}
// Synchronous Listener
document.addEventListener('readystatechange', function(){
if (document.readyState === 'complete'){
if(rscShouldLoad){
if(ConfigManager.isFirstLaunch()){
$('#welcomeContainer').fadeIn(500)
if(!fatalStartupError){
showMainUI()
} else {
$('#landingContainer').fadeIn(500)
showFatalStartupError()
}
}
} else if(document.readyState === 'interactive'){
//toggleOverlay(true, 'loadingContent')
}
/*if (document.readyState === 'interactive'){
@ -27,16 +72,19 @@ document.addEventListener('readystatechange', function(){
}, false)
// Actions that must be performed after the distribution index is downloaded.
ipcRenderer.on('distributionIndexDone', (data) => {
updateSelectedServer(AssetGuard.getServerById(ConfigManager.getLauncherDirectory(), ConfigManager.getSelectedServer()).name)
refreshServerStatus()
if(document.readyState === 'complete'){
if(ConfigManager.isFirstLaunch()){
$('#welcomeContainer').fadeIn(500)
ipcRenderer.on('distributionIndexDone', (event, data) => {
if(data != null) {
if(document.readyState === 'complete'){
showMainUI()
} else {
$('#landingContainer').fadeIn(500)
rscShouldLoad = true
}
} else {
rscShouldLoad = true
fatalStartupError = true
if(document.readyState === 'complete'){
showFatalStartupError()
} else {
rscShouldLoad = true
}
}
})

View File

@ -51,8 +51,8 @@ ipcMain.on('autoUpdateAction', (event, arg) => {
}
})
// Redirect distribution index event from preloader to renderer.
ipcMain.on('distributionIndexDone', (event, arg) => {
event.sender.send('distributionIndexDone', arg)
ipcMain.on('distributionIndexDone', (event, data) => {
event.sender.send('distributionIndexDone', data)
})
// Disable hardware acceleration.
@ -73,7 +73,7 @@ function createWindow() {
webPreferences: {
preload: path.join(__dirname, 'app', 'assets', 'js', 'preloader.js')
},
backgroundColor: '#2e2c29'
backgroundColor: '#171614'
})
ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length)))