mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
Merge branch 'master' of https://github.com/BoostIO/Boostnote into fixIssue2534
This commit is contained in:
@@ -2,7 +2,8 @@ import _ from 'lodash'
|
||||
import RcParser from 'browser/lib/RcParser'
|
||||
import i18n from 'browser/lib/i18n'
|
||||
import ee from 'browser/main/lib/eventEmitter'
|
||||
import {chooseTheme, applyTheme} from 'browser/main/lib/ThemeManager'
|
||||
import { chooseTheme, applyTheme } from 'browser/main/lib/ThemeManager'
|
||||
|
||||
const OSX = global.process.platform === 'darwin'
|
||||
const win = global.process.platform === 'win32'
|
||||
const electron = require('electron')
|
||||
@@ -26,12 +27,16 @@ export const DEFAULT_CONFIG = {
|
||||
},
|
||||
sortTagsBy: 'ALPHABETICAL', // 'ALPHABETICAL', 'COUNTER'
|
||||
listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL'
|
||||
listDirection: 'ASCENDING', // 'ASCENDING', 'DESCENDING'
|
||||
amaEnabled: true,
|
||||
autoUpdateEnabled: true,
|
||||
hotkey: {
|
||||
toggleMain: OSX ? 'Command + Alt + L' : 'Super + Alt + E',
|
||||
toggleMode: OSX ? 'Command + Alt + M' : 'Ctrl + M',
|
||||
deleteNote: OSX ? 'Command + Shift + Backspace' : 'Ctrl + Shift + Backspace',
|
||||
toggleDirection: OSX ? 'Command + Alt + Right' : 'Ctrl + Right',
|
||||
deleteNote: OSX
|
||||
? 'Command + Shift + Backspace'
|
||||
: 'Ctrl + Shift + Backspace',
|
||||
pasteSmartly: OSX ? 'Command + Shift + V' : 'Ctrl + Shift + V',
|
||||
prettifyMarkdown: OSX ? 'Command + Shift + F' : 'Ctrl + Shift + F',
|
||||
sortLines: OSX ? 'Command + Shift + S' : 'Ctrl + Shift + S',
|
||||
@@ -49,6 +54,7 @@ export const DEFAULT_CONFIG = {
|
||||
scheduleEnd: 360,
|
||||
showCopyNotification: true,
|
||||
disableDirectWrite: false,
|
||||
showScrollBar: true,
|
||||
defaultNote: 'ALWAYS_ASK', // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE'
|
||||
showMenuBar: false
|
||||
},
|
||||
@@ -80,7 +86,7 @@ export const DEFAULT_CONFIG = {
|
||||
customMarkdownLintConfig: DEFAULT_MARKDOWN_LINT_CONFIG,
|
||||
prettierConfig: ` {
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 4,
|
||||
"tabWidth": 2,
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
}`,
|
||||
@@ -119,7 +125,7 @@ export const DEFAULT_CONFIG = {
|
||||
coloredTags: {}
|
||||
}
|
||||
|
||||
function validate (config) {
|
||||
function validate(config) {
|
||||
if (!_.isObject(config)) return false
|
||||
if (!_.isNumber(config.zoom) || config.zoom < 0) return false
|
||||
if (!_.isBoolean(config.isSideNavFolded)) return false
|
||||
@@ -128,13 +134,17 @@ function validate (config) {
|
||||
return true
|
||||
}
|
||||
|
||||
function _save (config) {
|
||||
function _save(config) {
|
||||
window.localStorage.setItem('config', JSON.stringify(config))
|
||||
}
|
||||
|
||||
function get () {
|
||||
function get() {
|
||||
const rawStoredConfig = window.localStorage.getItem('config')
|
||||
const storedConfig = Object.assign({}, DEFAULT_CONFIG, JSON.parse(rawStoredConfig))
|
||||
const storedConfig = Object.assign(
|
||||
{},
|
||||
DEFAULT_CONFIG,
|
||||
JSON.parse(rawStoredConfig)
|
||||
)
|
||||
let config = storedConfig
|
||||
|
||||
try {
|
||||
@@ -148,7 +158,10 @@ function get () {
|
||||
_save(config)
|
||||
}
|
||||
|
||||
config.autoUpdateEnabled = electronConfig.get('autoUpdateEnabled', config.autoUpdateEnabled)
|
||||
config.autoUpdateEnabled = electronConfig.get(
|
||||
'autoUpdateEnabled',
|
||||
config.autoUpdateEnabled
|
||||
)
|
||||
|
||||
if (!isInitialized) {
|
||||
isInitialized = true
|
||||
@@ -160,7 +173,9 @@ function get () {
|
||||
document.head.appendChild(editorTheme)
|
||||
}
|
||||
|
||||
const theme = consts.THEMES.find(theme => theme.name === config.editor.theme)
|
||||
const theme = consts.THEMES.find(
|
||||
theme => theme.name === config.editor.theme
|
||||
)
|
||||
|
||||
if (theme) {
|
||||
editorTheme.setAttribute('href', theme.path)
|
||||
@@ -172,7 +187,7 @@ function get () {
|
||||
return config
|
||||
}
|
||||
|
||||
function set (updates) {
|
||||
function set(updates) {
|
||||
const currentConfig = get()
|
||||
|
||||
const arrangedUpdates = updates
|
||||
@@ -180,7 +195,12 @@ function set (updates) {
|
||||
arrangedUpdates.preview.customCSS = DEFAULT_CONFIG.preview.customCSS
|
||||
}
|
||||
|
||||
const newConfig = Object.assign({}, DEFAULT_CONFIG, currentConfig, arrangedUpdates)
|
||||
const newConfig = Object.assign(
|
||||
{},
|
||||
DEFAULT_CONFIG,
|
||||
currentConfig,
|
||||
arrangedUpdates
|
||||
)
|
||||
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
|
||||
_save(newConfig)
|
||||
|
||||
@@ -197,7 +217,9 @@ function set (updates) {
|
||||
document.head.appendChild(editorTheme)
|
||||
}
|
||||
|
||||
const newTheme = consts.THEMES.find(theme => theme.name === newConfig.editor.theme)
|
||||
const newTheme = consts.THEMES.find(
|
||||
theme => theme.name === newConfig.editor.theme
|
||||
)
|
||||
|
||||
if (newTheme) {
|
||||
editorTheme.setAttribute('href', newTheme.path)
|
||||
@@ -211,20 +233,45 @@ function set (updates) {
|
||||
ee.emit('config-renew')
|
||||
}
|
||||
|
||||
function assignConfigValues (originalConfig, rcConfig) {
|
||||
function assignConfigValues(originalConfig, rcConfig) {
|
||||
const config = Object.assign({}, DEFAULT_CONFIG, originalConfig, rcConfig)
|
||||
config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, originalConfig.hotkey, rcConfig.hotkey)
|
||||
config.blog = Object.assign({}, DEFAULT_CONFIG.blog, originalConfig.blog, rcConfig.blog)
|
||||
config.ui = Object.assign({}, DEFAULT_CONFIG.ui, originalConfig.ui, rcConfig.ui)
|
||||
config.editor = Object.assign({}, DEFAULT_CONFIG.editor, originalConfig.editor, rcConfig.editor)
|
||||
config.preview = Object.assign({}, DEFAULT_CONFIG.preview, originalConfig.preview, rcConfig.preview)
|
||||
config.hotkey = Object.assign(
|
||||
{},
|
||||
DEFAULT_CONFIG.hotkey,
|
||||
originalConfig.hotkey,
|
||||
rcConfig.hotkey
|
||||
)
|
||||
config.blog = Object.assign(
|
||||
{},
|
||||
DEFAULT_CONFIG.blog,
|
||||
originalConfig.blog,
|
||||
rcConfig.blog
|
||||
)
|
||||
config.ui = Object.assign(
|
||||
{},
|
||||
DEFAULT_CONFIG.ui,
|
||||
originalConfig.ui,
|
||||
rcConfig.ui
|
||||
)
|
||||
config.editor = Object.assign(
|
||||
{},
|
||||
DEFAULT_CONFIG.editor,
|
||||
originalConfig.editor,
|
||||
rcConfig.editor
|
||||
)
|
||||
config.preview = Object.assign(
|
||||
{},
|
||||
DEFAULT_CONFIG.preview,
|
||||
originalConfig.preview,
|
||||
rcConfig.preview
|
||||
)
|
||||
|
||||
rewriteHotkey(config)
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
function rewriteHotkey (config) {
|
||||
function rewriteHotkey(config) {
|
||||
const keys = [...Object.keys(config.hotkey)]
|
||||
keys.forEach(key => {
|
||||
config.hotkey[key] = config.hotkey[key].replace(/Cmd\s/g, 'Command ')
|
||||
|
||||
Reference in New Issue
Block a user