mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Fix ConfigManger to load the settings from localStorage properly
This commit is contained in:
@@ -60,19 +60,18 @@ function _save (config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get () {
|
function get () {
|
||||||
let config = window.localStorage.getItem('config')
|
const storedConfig = window.localStorage.getItem('config')
|
||||||
|
let config = storedConfig
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const boostnotercConfig = RcParser.parse()
|
const boostnotercConfig = RcParser.parse()
|
||||||
|
|
||||||
config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config))
|
config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(storedConfig))
|
||||||
|
config = assignConfigValues(config, boostnotercConfig)
|
||||||
config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig)
|
|
||||||
config = assignConfigValues(config, boostnotercConfig, config)
|
|
||||||
|
|
||||||
if (!validate(config)) throw new Error('INVALID CONFIG')
|
if (!validate(config)) throw new Error('INVALID CONFIG')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Boostnote resets the malformed configuration.')
|
console.warn('Boostnote resets the invalid configuration.')
|
||||||
config = DEFAULT_CONFIG
|
config = DEFAULT_CONFIG
|
||||||
_save(config)
|
_save(config)
|
||||||
}
|
}
|
||||||
@@ -131,12 +130,12 @@ function set (updates) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function assignConfigValues (config, rcConfig, originalConfig) {
|
function assignConfigValues (originalConfig, rcConfig) {
|
||||||
config = Object.assign({}, DEFAULT_CONFIG, rcConfig, originalConfig)
|
let config = Object.assign({}, DEFAULT_CONFIG, originalConfig, rcConfig)
|
||||||
config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, rcConfig.hotkey, originalConfig.hotkey)
|
config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, originalConfig.hotkey, rcConfig.hotkey)
|
||||||
config.ui = Object.assign({}, DEFAULT_CONFIG.ui, rcConfig.ui, originalConfig.ui)
|
config.ui = Object.assign({}, DEFAULT_CONFIG.ui, originalConfig.ui, rcConfig.ui)
|
||||||
config.editor = Object.assign({}, DEFAULT_CONFIG.editor, rcConfig.editor, originalConfig.editor)
|
config.editor = Object.assign({}, DEFAULT_CONFIG.editor, originalConfig.editor, rcConfig.editor)
|
||||||
config.preview = Object.assign({}, DEFAULT_CONFIG.preview, rcConfig.preview, originalConfig.preview)
|
config.preview = Object.assign({}, DEFAULT_CONFIG.preview, originalConfig.preview, rcConfig.preview)
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user