1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Merge pull request #783 from asmsuechan/add-boostnoterc-for-config

Add boostnoterc revival
This commit is contained in:
SuenagaRyota
2017-08-10 16:58:23 +09:00
committed by GitHub
3 changed files with 65 additions and 4 deletions

32
.boostnoterc.sample Normal file
View File

@@ -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
}

View File

@@ -1,10 +1,13 @@
import _ from 'lodash' import _ from 'lodash'
import RcParser from 'browser/main/lib/RcParser'
const OSX = global.process.platform === 'darwin' const OSX = global.process.platform === 'darwin'
const win = global.process.platform === 'win32' const win = global.process.platform === 'win32'
const electron = require('electron') const electron = require('electron')
const { ipcRenderer } = electron const { ipcRenderer } = electron
const consts = require('browser/lib/consts') const consts = require('browser/lib/consts')
const path = require('path')
const fs = require('fs')
let isInitialized = false let isInitialized = false
@@ -60,11 +63,13 @@ function get () {
let config = window.localStorage.getItem('config') let config = window.localStorage.getItem('config')
try { try {
const boostnotercConfig = RcParser.parse()
config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config)) 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 = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig)
config.editor = Object.assign({}, DEFAULT_CONFIG.editor, config.editor) config = assignConfigValues(config, boostnotercConfig, config)
config.preview = Object.assign({}, DEFAULT_CONFIG.preview, config.preview)
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 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 { export default {
get, get,
set, set,

View File

@@ -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
}