From 6e2e48fa64d511dde6c5d1203b5dff784c75d3e8 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Thu, 10 Aug 2017 23:19:57 +0900 Subject: [PATCH 1/3] Fix ConfigManger to load the settings from localStorage properly --- browser/main/lib/ConfigManager.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 505e7abd..b7397f88 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -60,19 +60,18 @@ function _save (config) { } function get () { - let config = window.localStorage.getItem('config') + const storedConfig = window.localStorage.getItem('config') + let config = storedConfig try { const boostnotercConfig = RcParser.parse() - config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config)) - - config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig) - config = assignConfigValues(config, boostnotercConfig, config) + config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(storedConfig)) + config = assignConfigValues(config, boostnotercConfig) if (!validate(config)) throw new Error('INVALID CONFIG') } catch (err) { - console.warn('Boostnote resets the malformed configuration.') + console.warn('Boostnote resets the invalid configuration.') config = DEFAULT_CONFIG _save(config) } @@ -131,12 +130,12 @@ function set (updates) { }) } -function assignConfigValues (config, rcConfig, originalConfig) { - config = Object.assign({}, DEFAULT_CONFIG, rcConfig, originalConfig) - config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, rcConfig.hotkey, originalConfig.hotkey) - config.ui = Object.assign({}, DEFAULT_CONFIG.ui, rcConfig.ui, originalConfig.ui) - config.editor = Object.assign({}, DEFAULT_CONFIG.editor, rcConfig.editor, originalConfig.editor) - config.preview = Object.assign({}, DEFAULT_CONFIG.preview, rcConfig.preview, originalConfig.preview) +function assignConfigValues (originalConfig, rcConfig) { + let config = Object.assign({}, DEFAULT_CONFIG, originalConfig, rcConfig) + config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, originalConfig.hotkey, rcConfig.hotkey) + config.ui = Object.assign({}, DEFAULT_CONFIG.ui, originalConfig.ui, rcConfig.ui) + config.editor = Object.assign({}, DEFAULT_CONFIG.editor, originalConfig.editor, rcConfig.editor) + config.preview = Object.assign({}, DEFAULT_CONFIG.preview, originalConfig.preview, rcConfig.preview) return config } From 821a7c780e109d4ad467be6d874b6569a50252bf Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Thu, 10 Aug 2017 23:30:42 +0900 Subject: [PATCH 2/3] Change variable names --- browser/main/lib/ConfigManager.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index b7397f88..62730463 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -60,14 +60,13 @@ function _save (config) { } function get () { - const storedConfig = window.localStorage.getItem('config') + const rawStoredConfig = window.localStorage.getItem('config') + const storedConfig = Object.assign({}, DEFAULT_CONFIG, JSON.parse(rawStoredConfig)) let config = storedConfig try { const boostnotercConfig = RcParser.parse() - - config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(storedConfig)) - config = assignConfigValues(config, boostnotercConfig) + config = assignConfigValues(storedConfig, boostnotercConfig) if (!validate(config)) throw new Error('INVALID CONFIG') } catch (err) { From cc1c7f3820608894f147892835df85ec4001a070 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 11 Aug 2017 00:30:57 +0900 Subject: [PATCH 3/3] Fix stupid JSON --- .boostnoterc.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.boostnoterc.sample b/.boostnoterc.sample index 10ef26d1..25b7e64f 100644 --- a/.boostnoterc.sample +++ b/.boostnoterc.sample @@ -20,7 +20,7 @@ "codeBlockTheme": "dracula", "fontFamily": "Lato", "fontSize": "14", - "lineNumber": true, + "lineNumber": true }, "sortBy": "UPDATED_AT", "ui": {