mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Merge pull request #783 from asmsuechan/add-boostnoterc-for-config
Add boostnoterc revival
This commit is contained in:
@@ -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,
|
||||
|
||||
15
browser/main/lib/RcParser.js
Normal file
15
browser/main/lib/RcParser.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user