1
0
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 fix-2903

This commit is contained in:
Callum Booth
2020-04-18 13:54:27 +01:00
287 changed files with 13790 additions and 8984 deletions

View File

@@ -8,6 +8,7 @@ const win = global.process.platform === 'win32'
const electron = require('electron')
const { ipcRenderer } = electron
const consts = require('browser/lib/consts')
const electronConfig = new (require('electron-config'))()
let isInitialized = false
@@ -15,6 +16,22 @@ const DEFAULT_MARKDOWN_LINT_CONFIG = `{
"default": true
}`
const DEFAULT_CSS_CONFIG = `
/* Drop Your Custom CSS Code Here */
[data-theme="default"] p code,
[data-theme="default"] li code,
[data-theme="default"] td code
{
padding: 2px;
border-width: 1px;
border-style: solid;
border-radius: 5px;
background-color: #F4F4F4;
border-color: #d9d9d9;
color: #03C588;
}
`
export const DEFAULT_CONFIG = {
zoom: 1,
isSideNavFolded: false,
@@ -25,13 +42,19 @@ 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 + Alt + Right',
deleteNote: OSX
? 'Command + Shift + Backspace'
: 'Ctrl + Shift + Backspace',
pasteSmartly: OSX ? 'Command + Shift + V' : 'Ctrl + Shift + V',
prettifyMarkdown: 'Shift + F',
prettifyMarkdown: OSX ? 'Command + Shift + F' : 'Ctrl + Shift + F',
sortLines: OSX ? 'Command + Shift + S' : 'Ctrl + Shift + S',
insertDate: OSX ? 'Command + /' : 'Ctrl + /',
insertDateTime: OSX ? 'Command + Alt + /' : 'Ctrl + Shift + /',
toggleMenuBar: 'Alt'
@@ -39,8 +62,14 @@ export const DEFAULT_CONFIG = {
ui: {
language: 'en',
theme: 'default',
defaultTheme: 'default',
enableScheduleTheme: false,
scheduledTheme: 'monokai',
scheduleStart: 1200,
scheduleEnd: 360,
showCopyNotification: true,
disableDirectWrite: false,
showScrollBar: true,
defaultNote: 'ALWAYS_ASK', // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE'
showMenuBar: false,
isStacking: false
@@ -71,13 +100,14 @@ export const DEFAULT_CONFIG = {
enableSmartPaste: false,
enableMarkdownLint: false,
customMarkdownLintConfig: DEFAULT_MARKDOWN_LINT_CONFIG,
prettierConfig: ` {
prettierConfig: `{
"trailingComma": "es5",
"tabWidth": 4,
"tabWidth": 2,
"semi": false,
"singleQuote": true
}`,
deleteUnusedAttachments: true
deleteUnusedAttachments: true,
rtlEnabled: false
},
preview: {
fontSize: '14',
@@ -95,8 +125,7 @@ export const DEFAULT_CONFIG = {
breaks: true,
smartArrows: false,
allowCustomCSS: false,
customCSS: '/* Drop Your Custom CSS Code Here */',
customCSS: DEFAULT_CSS_CONFIG,
sanitize: 'STRICT', // 'STRICT', 'ALLOW_STYLES', 'NONE'
mermaidHTMLLabel: false,
lineThroughCheckbox: true
@@ -112,7 +141,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
@@ -121,13 +150,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 {
@@ -141,6 +174,11 @@ function get () {
_save(config)
}
config.autoUpdateEnabled = electronConfig.get(
'autoUpdateEnabled',
config.autoUpdateEnabled
)
if (!isInitialized) {
isInitialized = true
let editorTheme = document.getElementById('editorTheme')
@@ -151,7 +189,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)
@@ -163,7 +203,7 @@ function get () {
return config
}
function set (updates) {
function set(updates) {
const currentConfig = get()
const arrangedUpdates = updates
@@ -171,24 +211,15 @@ 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)
if (newConfig.ui.theme === 'dark') {
document.body.setAttribute('data-theme', 'dark')
} else if (newConfig.ui.theme === 'white') {
document.body.setAttribute('data-theme', 'white')
} else if (newConfig.ui.theme === 'solarized-dark') {
document.body.setAttribute('data-theme', 'solarized-dark')
} else if (newConfig.ui.theme === 'monokai') {
document.body.setAttribute('data-theme', 'monokai')
} else if (newConfig.ui.theme === 'dracula') {
document.body.setAttribute('data-theme', 'dracula')
} else {
document.body.setAttribute('data-theme', 'default')
}
i18n.setLocale(newConfig.ui.language)
let editorTheme = document.getElementById('editorTheme')
@@ -199,32 +230,61 @@ 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)
}
electronConfig.set('autoUpdateEnabled', newConfig.autoUpdateEnabled)
ipcRenderer.send('config-renew', {
config: get()
})
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 ')