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

enhance applying config

This commit is contained in:
Rokt33r
2016-01-10 04:25:00 +09:00
parent c14827b234
commit 5df0755252
7 changed files with 62 additions and 32 deletions

View File

@@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
import ReactDOM from 'react-dom'
import modes from '../lib/modes'
import _ from 'lodash'
import fetchConfig from '../lib/fetchConfig'
const electron = require('electron')
const remote = electron.remote
@@ -9,17 +10,16 @@ const ipc = electron.ipcRenderer
const ace = window.ace
function getConfig () {
return Object.assign({}, remote.getGlobal('config'))
}
let config = getConfig()
let config = fetchConfig()
ipc.on('config-apply', function (e, newConfig) {
config = newConfig
})
export default class CodeEditor extends React.Component {
constructor (props) {
super(props)
this.configApplyHandler = e => this.handleConfigApply(e)
this.configApplyHandler = (e, config) => this.handleConfigApply(e, config)
this.changeHandler = e => this.handleChange(e)
this.state = {
@@ -111,8 +111,7 @@ export default class CodeEditor extends React.Component {
}
}
handleConfigApply () {
config = getConfig()
handleConfigApply (e, config) {
this.setState({
fontSize: config['editor-font-size'],
fontFamily: config['editor-font-family'],

View File

@@ -3,10 +3,10 @@ import markdown from '../lib/markdown'
import ReactDOM from 'react-dom'
import sanitizeHtml from '@rokt33r/sanitize-html'
import _ from 'lodash'
import fetchConfig from '../lib/fetchConfig'
const electron = require('electron')
const shell = electron.shell
const remote = electron.remote
const ipc = electron.ipcRenderer
const katex = window.katex
@@ -66,17 +66,16 @@ function math2Katex (display) {
}
}
function getConfig () {
return Object.assign({}, remote.getGlobal('config'))
}
let config = getConfig()
let config = fetchConfig()
ipc.on('config-apply', function (e, newConfig) {
config = newConfig
})
export default class MarkdownPreview extends React.Component {
constructor (props) {
super(props)
this.configApplyHandler = e => this.handleConfigApply(e)
this.configApplyHandler = (e, config) => this.handleConfigApply(e, config)
this.state = {
fontSize: config['preview-font-size'],
@@ -160,8 +159,7 @@ export default class MarkdownPreview extends React.Component {
}
}
handleConfigApply () {
config = getConfig()
handleConfigApply (e, config) {
this.setState({
fontSize: config['preview-font-size'],
fontFamily: config['preview-font-family']

View File

@@ -0,0 +1,10 @@
const electron = require('electron')
const remote = electron.remote
const jetpack = require('fs-jetpack')
const userDataPath = remote.app.getPath('userData')
const configFile = 'config.json'
export default function fetchConfig () {
return Object.assign({}, JSON.parse(jetpack.cwd(userDataPath).read(configFile, 'utf-8')))
}

View File

@@ -1,6 +1,7 @@
import React, { PropTypes } from 'react'
import linkState from 'browser/lib/linkState'
import { updateUser } from '../../actions'
import fetchConfig from 'browser/lib/fetchConfig'
const electron = require('electron')
const ipc = electron.ipcRenderer
@@ -12,7 +13,7 @@ export default class AppSettingTab extends React.Component {
constructor (props) {
super(props)
let keymap = Object.assign({}, remote.getGlobal('keymap'))
let config = Object.assign({}, remote.getGlobal('config'))
let config = Object.assign({}, fetchConfig())
let userName = props.user != null ? props.user.name : null
this.state = {