mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
enhance applying config
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
|
|||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import modes from '../lib/modes'
|
import modes from '../lib/modes'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
import fetchConfig from '../lib/fetchConfig'
|
||||||
|
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const remote = electron.remote
|
const remote = electron.remote
|
||||||
@@ -9,17 +10,16 @@ const ipc = electron.ipcRenderer
|
|||||||
|
|
||||||
const ace = window.ace
|
const ace = window.ace
|
||||||
|
|
||||||
function getConfig () {
|
let config = fetchConfig()
|
||||||
return Object.assign({}, remote.getGlobal('config'))
|
ipc.on('config-apply', function (e, newConfig) {
|
||||||
}
|
config = newConfig
|
||||||
|
})
|
||||||
let config = getConfig()
|
|
||||||
|
|
||||||
export default class CodeEditor extends React.Component {
|
export default class CodeEditor extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.configApplyHandler = e => this.handleConfigApply(e)
|
this.configApplyHandler = (e, config) => this.handleConfigApply(e, config)
|
||||||
this.changeHandler = e => this.handleChange(e)
|
this.changeHandler = e => this.handleChange(e)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -111,8 +111,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleConfigApply () {
|
handleConfigApply (e, config) {
|
||||||
config = getConfig()
|
|
||||||
this.setState({
|
this.setState({
|
||||||
fontSize: config['editor-font-size'],
|
fontSize: config['editor-font-size'],
|
||||||
fontFamily: config['editor-font-family'],
|
fontFamily: config['editor-font-family'],
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import markdown from '../lib/markdown'
|
|||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import sanitizeHtml from '@rokt33r/sanitize-html'
|
import sanitizeHtml from '@rokt33r/sanitize-html'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
import fetchConfig from '../lib/fetchConfig'
|
||||||
|
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const shell = electron.shell
|
const shell = electron.shell
|
||||||
const remote = electron.remote
|
|
||||||
const ipc = electron.ipcRenderer
|
const ipc = electron.ipcRenderer
|
||||||
|
|
||||||
const katex = window.katex
|
const katex = window.katex
|
||||||
@@ -66,17 +66,16 @@ function math2Katex (display) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConfig () {
|
let config = fetchConfig()
|
||||||
return Object.assign({}, remote.getGlobal('config'))
|
ipc.on('config-apply', function (e, newConfig) {
|
||||||
}
|
config = newConfig
|
||||||
|
})
|
||||||
let config = getConfig()
|
|
||||||
|
|
||||||
export default class MarkdownPreview extends React.Component {
|
export default class MarkdownPreview extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.configApplyHandler = e => this.handleConfigApply(e)
|
this.configApplyHandler = (e, config) => this.handleConfigApply(e, config)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
fontSize: config['preview-font-size'],
|
fontSize: config['preview-font-size'],
|
||||||
@@ -160,8 +159,7 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleConfigApply () {
|
handleConfigApply (e, config) {
|
||||||
config = getConfig()
|
|
||||||
this.setState({
|
this.setState({
|
||||||
fontSize: config['preview-font-size'],
|
fontSize: config['preview-font-size'],
|
||||||
fontFamily: config['preview-font-family']
|
fontFamily: config['preview-font-family']
|
||||||
|
|||||||
10
browser/lib/fetchConfig.js
Normal file
10
browser/lib/fetchConfig.js
Normal 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')))
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { PropTypes } from 'react'
|
import React, { PropTypes } from 'react'
|
||||||
import linkState from 'browser/lib/linkState'
|
import linkState from 'browser/lib/linkState'
|
||||||
import { updateUser } from '../../actions'
|
import { updateUser } from '../../actions'
|
||||||
|
import fetchConfig from 'browser/lib/fetchConfig'
|
||||||
|
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const ipc = electron.ipcRenderer
|
const ipc = electron.ipcRenderer
|
||||||
@@ -12,7 +13,7 @@ export default class AppSettingTab extends React.Component {
|
|||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
let keymap = Object.assign({}, remote.getGlobal('keymap'))
|
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
|
let userName = props.user != null ? props.user.name : null
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const electron = require('electron')
|
|||||||
const app = electron.app
|
const app = electron.app
|
||||||
const ipc = electron.ipcMain
|
const ipc = electron.ipcMain
|
||||||
const jetpack = require('fs-jetpack')
|
const jetpack = require('fs-jetpack')
|
||||||
|
const nodeIpc = require('@rokt33r/node-ipc')
|
||||||
|
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
'editor-font-size': '14',
|
'editor-font-size': '14',
|
||||||
@@ -23,35 +24,53 @@ function getConfig () {
|
|||||||
return JSON.parse(jetpack.cwd(userDataPath).read(configFile, 'utf-8'))
|
return JSON.parse(jetpack.cwd(userDataPath).read(configFile, 'utf-8'))
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
return {}
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var config = null
|
||||||
|
|
||||||
function saveConfig () {
|
function saveConfig () {
|
||||||
var content
|
var content
|
||||||
try {
|
try {
|
||||||
content = JSON.stringify(global.config)
|
content = JSON.stringify(config)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
global.config = {}
|
config = {}
|
||||||
content = JSON.stringify(global.config)
|
content = JSON.stringify(config)
|
||||||
}
|
}
|
||||||
jetpack.cwd(userDataPath).file(configFile, { content })
|
jetpack.cwd(userDataPath).file(configFile, { content })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
global.config = Object.assign({}, defaultConfig, getConfig())
|
config = getConfig()
|
||||||
|
if (config == null) {
|
||||||
|
config = Object.assign({}, defaultConfig)
|
||||||
|
saveConfig()
|
||||||
|
}
|
||||||
|
|
||||||
if (global.config['disable-direct-write']) {
|
config = Object.assign({}, defaultConfig, config)
|
||||||
|
|
||||||
|
if (config['disable-direct-write']) {
|
||||||
app.commandLine.appendSwitch('disable-direct-write')
|
app.commandLine.appendSwitch('disable-direct-write')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function emitToFinder (type, data) {
|
||||||
|
var payload = {
|
||||||
|
type: type,
|
||||||
|
data: data
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeIpc.server.broadcast('message', payload)
|
||||||
|
}
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
const mainWindow = require('./main-window')
|
const mainWindow = require('./main-window')
|
||||||
function applyConfig () {
|
function applyConfig () {
|
||||||
mainWindow.webContents.send('config-apply')
|
mainWindow.webContents.send('config-apply', config)
|
||||||
|
emitToFinder('config-apply', config)
|
||||||
}
|
}
|
||||||
|
|
||||||
ipc.on('configUpdated', function (event, newConfig) {
|
ipc.on('configUpdated', function (event, newConfig) {
|
||||||
global.config = Object.assign({}, defaultConfig, global.config, newConfig)
|
config = Object.assign({}, defaultConfig, config, newConfig)
|
||||||
saveConfig()
|
saveConfig()
|
||||||
applyConfig()
|
applyConfig()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -45,16 +45,20 @@ nodeIpc.connectTo(
|
|||||||
nodeIpc.of.main.on(
|
nodeIpc.of.main.on(
|
||||||
'message',
|
'message',
|
||||||
function (payload) {
|
function (payload) {
|
||||||
switch (payload.type) {
|
if (isFinderLoaded) {
|
||||||
case 'open-finder':
|
switch (payload.type) {
|
||||||
if (isFinderLoaded) {
|
case 'open-finder':
|
||||||
if (finderWindow.isFocused()) {
|
if (finderWindow.isFocused()) {
|
||||||
hideFinder()
|
hideFinder()
|
||||||
} else {
|
} else {
|
||||||
openFinder()
|
openFinder()
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
case 'config-apply': {
|
||||||
|
finderWindow.webContents.send('config-apply', payload.data)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
break
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ updater.on('update-downloaded', (info) => {
|
|||||||
|
|
||||||
nodeIpc.config.id = 'node'
|
nodeIpc.config.id = 'node'
|
||||||
nodeIpc.config.retry = 1500
|
nodeIpc.config.retry = 1500
|
||||||
// nodeIpc.config.silent = true
|
nodeIpc.config.silent = true
|
||||||
|
|
||||||
function spawnFinder() {
|
function spawnFinder() {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
@@ -276,7 +276,6 @@ app.on('ready', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (finderProcess == null && process.platform === 'darwin') {
|
if (finderProcess == null && process.platform === 'darwin') {
|
||||||
console.log('fired only once ')
|
|
||||||
spawnFinder()
|
spawnFinder()
|
||||||
} else {
|
} else {
|
||||||
finderWindow = require('./finder-window')
|
finderWindow = require('./finder-window')
|
||||||
|
|||||||
Reference in New Issue
Block a user