From 4f416220c241db26634298e2f95902b56e6032e9 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Mon, 13 Aug 2018 06:31:46 -0400 Subject: [PATCH] Added failsafe to configuration loading. If file is malformed or corrupt, generate a fresh configuration file. --- app/assets/js/configmanager.js | 19 ++++++++++++++++--- app/assets/js/scripts/settings.js | 9 +++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/assets/js/configmanager.js b/app/assets/js/configmanager.js index aea5d13..de4756a 100644 --- a/app/assets/js/configmanager.js +++ b/app/assets/js/configmanager.js @@ -101,9 +101,22 @@ exports.load = function(){ config = DEFAULT_CONFIG exports.save() } else { - config = JSON.parse(fs.readFileSync(filePath, 'UTF-8')) - config = validateKeySet(DEFAULT_CONFIG, config) - exports.save() + let doValidate = false + try { + config = JSON.parse(fs.readFileSync(filePath, 'UTF-8')) + doValidate = true + } catch (err){ + console.error(err) + console.log('%c[ConfigManager]', 'color: #a02d2a; font-weight: bold', 'Configuration file contains malformed JSON or is corrupt.') + console.log('%c[ConfigManager]', 'color: #a02d2a; font-weight: bold', 'Generating a new configuration file.') + mkpath.sync(path.join(filePath, '..')) + config = DEFAULT_CONFIG + exports.save() + } + if(doValidate){ + config = validateKeySet(DEFAULT_CONFIG, config) + exports.save() + } } console.log('%c[ConfigManager]', 'color: #a02d2a; font-weight: bold', 'Successfully Loaded') } diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index 52063b0..817cf26 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -361,6 +361,9 @@ const settingsCurrentAccounts = document.getElementById('settingsCurrentAccounts function populateAuthAccounts(){ const authAccounts = ConfigManager.getAuthAccounts() const authKeys = Object.keys(authAccounts) + if(authKeys.length === 0){ + return + } const selectedUUID = ConfigManager.getSelectedAccount().uuid let authAccountStr = '' @@ -1112,8 +1115,10 @@ function populateSettingsUpdateInformation(data){ settingsUpdateChangelogCont.style.display = 'none' populateVersionInformation(remote.app.getVersion(), settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck) settingsUpdateButtonStatus('Check for Updates', false, () => { - ipcRenderer.send('autoUpdateAction', 'checkForUpdate') - settingsUpdateButtonStatus('Checking for Updates..', true) + if(!isDev){ + ipcRenderer.send('autoUpdateAction', 'checkForUpdate') + settingsUpdateButtonStatus('Checking for Updates..', true) + } }) } }