diff --git a/.boostnoterc.sample b/.boostnoterc.sample new file mode 100644 index 00000000..10ef26d1 --- /dev/null +++ b/.boostnoterc.sample @@ -0,0 +1,32 @@ +{ + "editor": { + "fontFamily": "Monaco, Consolas", + "fontSize": "14", + "indentSize": "2", + "indentType": "space", + "keyMap": "vim", + "switchPreview": "BLUR", + "theme": "monokai" + }, + "hotkey": { + "toggleFinder": "Cmd + Alt + S", + "toggleMain": "Cmd + Alt + L" + }, + "isSideNavFolded": false, + "listStyle": "DEFAULT", + "listWidth": 174, + "navWidth": 200, + "preview": { + "codeBlockTheme": "dracula", + "fontFamily": "Lato", + "fontSize": "14", + "lineNumber": true, + }, + "sortBy": "UPDATED_AT", + "ui": { + "defaultNote": "ALWAYS_ASK", + "disableDirectWrite": false, + "theme": "default" + }, + "zoom": 1 +} diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 6752fc14..505e7abd 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -1,10 +1,13 @@ import _ from 'lodash' +import RcParser from 'browser/main/lib/RcParser' const OSX = global.process.platform === 'darwin' const win = global.process.platform === 'win32' const electron = require('electron') const { ipcRenderer } = electron const consts = require('browser/lib/consts') +const path = require('path') +const fs = require('fs') let isInitialized = false @@ -60,11 +63,13 @@ function get () { let config = window.localStorage.getItem('config') try { + const boostnotercConfig = RcParser.parse() + config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config)) - config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, config.hotkey) - config.ui = Object.assign({}, DEFAULT_CONFIG.ui, config.ui) - config.editor = Object.assign({}, DEFAULT_CONFIG.editor, config.editor) - config.preview = Object.assign({}, DEFAULT_CONFIG.preview, config.preview) + + config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig) + config = assignConfigValues(config, boostnotercConfig, config) + if (!validate(config)) throw new Error('INVALID CONFIG') } catch (err) { console.warn('Boostnote resets the malformed configuration.') @@ -126,6 +131,15 @@ 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) + return config +} + export default { get, set, diff --git a/browser/main/lib/RcParser.js b/browser/main/lib/RcParser.js new file mode 100644 index 00000000..2bb7f6a6 --- /dev/null +++ b/browser/main/lib/RcParser.js @@ -0,0 +1,15 @@ +import path from 'path' +import sander from 'sander' + +function parse () { + const BOOSTNOTERC = '.boostnoterc' + const homePath = global.process.env.HOME || global.process.env.USERPROFILE + const boostnotercPath = path.join(homePath, BOOSTNOTERC) + + if (!sander.existsSync(boostnotercPath)) return {} + return JSON.parse(sander.readFileSync(boostnotercPath).toString()) +} + +export default { + parse +}