mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Enable to set configs in ~/.boostnoterc
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
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')
|
||||||
|
const BOOSTNOTERC = '.boostnoterc'
|
||||||
|
|
||||||
let isInitialized = false
|
let isInitialized = false
|
||||||
|
|
||||||
@@ -60,11 +64,25 @@ function get () {
|
|||||||
let config = window.localStorage.getItem('config')
|
let config = window.localStorage.getItem('config')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const homePath = global.process.env.HOME || global.process.env.USERPROFILE
|
||||||
|
const boostnotercPath = path.join(homePath, BOOSTNOTERC)
|
||||||
|
const boostnotercConfig = RcParser.parse(boostnotercPath)
|
||||||
|
|
||||||
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)
|
if (boostnotercConfig !== undefined) {
|
||||||
config.editor = Object.assign({}, DEFAULT_CONFIG.editor, config.editor)
|
config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, boostnotercConfig.hotkey)
|
||||||
config.preview = Object.assign({}, DEFAULT_CONFIG.preview, config.preview)
|
config.ui = Object.assign({}, DEFAULT_CONFIG.ui, boostnotercConfig.ui)
|
||||||
|
config.editor = Object.assign({}, DEFAULT_CONFIG.editor, boostnotercConfig.editor)
|
||||||
|
config.preview = Object.assign({}, DEFAULT_CONFIG.preview, boostnotercConfig.preview)
|
||||||
|
}
|
||||||
|
|
||||||
|
config = Object.assign(config, DEFAULT_CONFIG, config)
|
||||||
|
config.hotkey = Object.assign(config, DEFAULT_CONFIG.hotkey, config.hotkey)
|
||||||
|
config.ui = Object.assign(config, DEFAULT_CONFIG.ui, config.ui)
|
||||||
|
config.editor = Object.assign(config, DEFAULT_CONFIG.editor, config.editor)
|
||||||
|
config.preview = Object.assign(config, 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.')
|
||||||
|
|||||||
12
browser/main/lib/RcParser.js
Normal file
12
browser/main/lib/RcParser.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
const path = require('path')
|
||||||
|
const sander = require('sander')
|
||||||
|
|
||||||
|
function parse (boostnotercPath) {
|
||||||
|
if (!sander.existsSync(boostnotercPath)) return
|
||||||
|
let config = JSON.parse(sander.readFileSync(boostnotercPath).toString())
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
parse
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user