|
1 | 1 | import _ from 'lodash' |
| 2 | +import RcParser from 'browser/main/lib/RcParser' |
2 | 3 |
|
3 | 4 | const OSX = global.process.platform === 'darwin' |
4 | 5 | const win = global.process.platform === 'win32' |
5 | 6 | const electron = require('electron') |
6 | 7 | const { ipcRenderer } = electron |
7 | 8 | const consts = require('browser/lib/consts') |
| 9 | +const path = require('path') |
| 10 | +const fs = require('fs') |
8 | 11 |
|
9 | 12 | let isInitialized = false |
10 | 13 |
|
@@ -60,11 +63,13 @@ function get () { |
60 | 63 | let config = window.localStorage.getItem('config') |
61 | 64 |
|
62 | 65 | try { |
| 66 | + const boostnotercConfig = RcParser.parse() |
| 67 | + |
63 | 68 | config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config)) |
64 | | - config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, config.hotkey) |
65 | | - config.ui = Object.assign({}, DEFAULT_CONFIG.ui, config.ui) |
66 | | - config.editor = Object.assign({}, DEFAULT_CONFIG.editor, config.editor) |
67 | | - config.preview = Object.assign({}, DEFAULT_CONFIG.preview, config.preview) |
| 69 | + |
| 70 | + config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig) |
| 71 | + config = assignConfigValues(config, boostnotercConfig, config) |
| 72 | + |
68 | 73 | if (!validate(config)) throw new Error('INVALID CONFIG') |
69 | 74 | } catch (err) { |
70 | 75 | console.warn('Boostnote resets the malformed configuration.') |
@@ -126,6 +131,15 @@ function set (updates) { |
126 | 131 | }) |
127 | 132 | } |
128 | 133 |
|
| 134 | +function assignConfigValues (config, rcConfig, originalConfig) { |
| 135 | + config = Object.assign({}, DEFAULT_CONFIG, rcConfig, originalConfig) |
| 136 | + config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, rcConfig.hotkey, originalConfig.hotkey) |
| 137 | + config.ui = Object.assign({}, DEFAULT_CONFIG.ui, rcConfig.ui, originalConfig.ui) |
| 138 | + config.editor = Object.assign({}, DEFAULT_CONFIG.editor, rcConfig.editor, originalConfig.editor) |
| 139 | + config.preview = Object.assign({}, DEFAULT_CONFIG.preview, rcConfig.preview, originalConfig.preview) |
| 140 | + return config |
| 141 | +} |
| 142 | + |
129 | 143 | export default { |
130 | 144 | get, |
131 | 145 | set, |
|
0 commit comments