From 1261f97aa0d38a29f571addbfab6454704bfb500 Mon Sep 17 00:00:00 2001 From: sungshon <49482512+sungshon@users.noreply.github.com> Date: Fri, 7 Feb 2020 19:42:31 +0200 Subject: [PATCH] Fix user settings if default settings changed --- src/lib/config/userConfig.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib/config/userConfig.js b/src/lib/config/userConfig.js index bc80939..9d343f5 100644 --- a/src/lib/config/userConfig.js +++ b/src/lib/config/userConfig.js @@ -48,6 +48,19 @@ const defaultConfig = { let password = '' +// fixes settings if new properties were added / removed +function fixSettings(config) { + for (let key in defaultConfig.userDefined) + if (typeof config.userDefined[key] === 'undefined') + config.userDefined[key] = defaultConfig.userDefined[key] + + for (let key in config.userDefined) + if (typeof defaultConfig.userDefined[key] === 'undefined') + delete config.userDefined[key] + + return config +} + const configDb = { compress: data => { const obj = {} @@ -83,6 +96,8 @@ const configDb = { return defaultConfig } + config = fixSettings(config) + return config } else return defaultConfig @@ -104,6 +119,8 @@ const configDb = { return configDb.compress(defaultConfig) } + config = fixSettings(config) + const compressed = configDb.compress(config) if (!password && compressed.userDefined.password) password = compressed.userDefined.password