Skip to content

Commit 35938c0

Browse files
authored
Merge pull request #783 from asmsuechan/add-boostnoterc-for-config
Add boostnoterc revival
2 parents 9eaa90c + af91c40 commit 35938c0

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

.boostnoterc.sample

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"editor": {
3+
"fontFamily": "Monaco, Consolas",
4+
"fontSize": "14",
5+
"indentSize": "2",
6+
"indentType": "space",
7+
"keyMap": "vim",
8+
"switchPreview": "BLUR",
9+
"theme": "monokai"
10+
},
11+
"hotkey": {
12+
"toggleFinder": "Cmd + Alt + S",
13+
"toggleMain": "Cmd + Alt + L"
14+
},
15+
"isSideNavFolded": false,
16+
"listStyle": "DEFAULT",
17+
"listWidth": 174,
18+
"navWidth": 200,
19+
"preview": {
20+
"codeBlockTheme": "dracula",
21+
"fontFamily": "Lato",
22+
"fontSize": "14",
23+
"lineNumber": true,
24+
},
25+
"sortBy": "UPDATED_AT",
26+
"ui": {
27+
"defaultNote": "ALWAYS_ASK",
28+
"disableDirectWrite": false,
29+
"theme": "default"
30+
},
31+
"zoom": 1
32+
}

browser/main/lib/ConfigManager.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import _ from 'lodash'
2+
import RcParser from 'browser/main/lib/RcParser'
23

34
const OSX = global.process.platform === 'darwin'
45
const win = global.process.platform === 'win32'
56
const electron = require('electron')
67
const { ipcRenderer } = electron
78
const consts = require('browser/lib/consts')
9+
const path = require('path')
10+
const fs = require('fs')
811

912
let isInitialized = false
1013

@@ -60,11 +63,13 @@ function get () {
6063
let config = window.localStorage.getItem('config')
6164

6265
try {
66+
const boostnotercConfig = RcParser.parse()
67+
6368
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+
6873
if (!validate(config)) throw new Error('INVALID CONFIG')
6974
} catch (err) {
7075
console.warn('Boostnote resets the malformed configuration.')
@@ -126,6 +131,15 @@ function set (updates) {
126131
})
127132
}
128133

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+
129143
export default {
130144
get,
131145
set,

browser/main/lib/RcParser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import path from 'path'
2+
import sander from 'sander'
3+
4+
function parse () {
5+
const BOOSTNOTERC = '.boostnoterc'
6+
const homePath = global.process.env.HOME || global.process.env.USERPROFILE
7+
const boostnotercPath = path.join(homePath, BOOSTNOTERC)
8+
9+
if (!sander.existsSync(boostnotercPath)) return {}
10+
return JSON.parse(sander.readFileSync(boostnotercPath).toString())
11+
}
12+
13+
export default {
14+
parse
15+
}

0 commit comments

Comments
 (0)