diff --git a/app/app.ejs b/app/app.ejs index 2804847..cad811d 100644 --- a/app/app.ejs +++ b/app/app.ejs @@ -7,10 +7,13 @@ - + <% include frame.ejs %>
<% include welcome.ejs %> @@ -30,5 +33,13 @@ <% include landing.ejs %>
<% include overlay.ejs %> +
+
+
+ + +
+
+
\ No newline at end of file diff --git a/app/assets/css/launcher.css b/app/assets/css/launcher.css index 617c4f1..dbe41b1 100644 --- a/app/assets/css/launcher.css +++ b/app/assets/css/launcher.css @@ -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); @@ -2091,4 +2031,66 @@ 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; } \ No newline at end of file diff --git a/app/assets/js/assetexec.js b/app/assets/js/assetexec.js index 1660b30..ee3c25d 100644 --- a/app/assets/js/assetexec.js +++ b/app/assets/js/assetexec.js @@ -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}) diff --git a/app/assets/js/assetguard.js b/app/assets/js/assetguard.js index b925d33..4257938 100644 --- a/app/assets/js/assetguard.js +++ b/app/assets/js/assetguard.js @@ -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.} 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.} 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 { + + 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 diff --git a/app/assets/js/preloader.js b/app/assets/js/preloader.js index 99e04f8..2028048 100644 --- a/app/assets/js/preloader.js +++ b/app/assets/js/preloader.js @@ -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. diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index 799a8d3..db925a3 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -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'){ @@ -491,16 +508,30 @@ function dlAsync(login = true){ }, 750) } 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() \ No newline at end of file +} \ No newline at end of file diff --git a/app/assets/js/scripts/overlay.js b/app/assets/js/scripts/overlay.js index a24c85c..c509bde 100644 --- a/app/assets/js/scripts/overlay.js +++ b/app/assets/js/scripts/overlay.js @@ -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) diff --git a/app/assets/js/scripts/uibinder.js b/app/assets/js/scripts/uibinder.js index b7d2d71..ff288c8 100644 --- a/app/assets/js/scripts/uibinder.js +++ b/app/assets/js/scripts/uibinder.js @@ -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.

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 + } } }) diff --git a/index.js b/index.js index 72c9649..9f1692b 100644 --- a/index.js +++ b/index.js @@ -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)))