Skip to content

Commit

Permalink
Fix user settings if default settings changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sungshon authored Feb 7, 2020
1 parent d1c0c67 commit 1261f97
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/config/userConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -83,6 +96,8 @@ const configDb = {
return defaultConfig
}

config = fixSettings(config)

return config
} else
return defaultConfig
Expand All @@ -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
Expand Down

0 comments on commit 1261f97

Please sign in to comment.