From 52f694a714ea80ec980b5a612cdb1cd1bd113175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Sat, 19 May 2018 18:58:44 +0700 Subject: [PATCH 01/75] fixed null attachment --- browser/main/lib/dataApi/attachmentManagement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index efacd47c..7c4b46be 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -172,7 +172,7 @@ function getAttachmentsInContent (markdownContent) { * @returns {String[]} Absolute paths of the referenced attachments */ function getAbsolutePathsOfAttachmentsInContent (markdownContent, storagePath) { - const temp = getAttachmentsInContent(markdownContent) + const temp = getAttachmentsInContent(markdownContent) || [] const result = [] for (const relativePath of temp) { result.push(relativePath.replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER, 'g'), path.join(storagePath, DESTINATION_FOLDER))) From d6c28da3a8d61c149a2c5f9c6af46a1b57407f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Sat, 19 May 2018 19:39:08 +0700 Subject: [PATCH 02/75] added export escape html config --- browser/components/MarkdownPreview.js | 3 +- browser/main/lib/ConfigManager.js | 3 + .../main/modals/PreferencesModal/Export.js | 120 ++++++++++++++++++ browser/main/modals/PreferencesModal/index.js | 11 +- 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 browser/main/modals/PreferencesModal/Export.js diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 6646f749..ef11a0cc 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -15,6 +15,7 @@ import copy from 'copy-to-clipboard' import mdurl from 'mdurl' import exportNote from 'browser/main/lib/dataApi/exportNote' import { escapeHtmlCharacters } from 'browser/lib/utils' +import ConfigManager from 'browser/main/lib/ConfigManager' const { remote } = require('electron') const attachmentManagement = require('../main/lib/dataApi/attachmentManagement') @@ -218,7 +219,7 @@ export default class MarkdownPreview extends React.Component { const {fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme} = this.getStyleParams() const inlineStyles = buildStyle(fontFamily, fontSize, codeBlockFontFamily, lineNumber, scrollPastEnd, theme) - let body = this.markdown.render(escapeHtmlCharacters(noteContent)) + let body = this.markdown.render(ConfigManager.get().exports.escapeHtml ? escapeHtmlCharacters(noteContent) : noteContent) const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES] const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(noteContent, this.props.storagePath) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 79fe0f5f..5b263191 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -65,6 +65,9 @@ export const DEFAULT_CONFIG = { token: '', username: '', password: '' + }, + exports: { + escapeHtml: true } } diff --git a/browser/main/modals/PreferencesModal/Export.js b/browser/main/modals/PreferencesModal/Export.js new file mode 100644 index 00000000..ae57cc14 --- /dev/null +++ b/browser/main/modals/PreferencesModal/Export.js @@ -0,0 +1,120 @@ +import React from 'react' +import ConfigManager from 'browser/main/lib/ConfigManager' +import i18n from 'browser/lib/i18n' +import styles from './ConfigTab.styl' +import CSSModules from 'browser/lib/CSSModules' +import store from 'browser/main/store' + +const electron = require('electron') +const ipc = electron.ipcRenderer + +class Export extends React.Component { + constructor(props) { + super(props) + this.state = { + config: props.config + } + } + + componentDidMount () { + this.handleSettingDone = () => { + this.setState({ExportAlert: { + type: 'success', + message: i18n.__('Successfully applied!') + }}) + } + this.handleSettingError = (err) => { + this.setState({ExportAlert: { + type: 'error', + message: err.message != null ? err.message : i18n.__('Error occurs!') + }}) + } + ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) + ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) + } + + componentWillUnmount () { + ipc.removeListener('APP_SETTING_DONE', this.handleSettingDone) + ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError) + } + + handleUIChange (e) { + const newConfig = { + exports: { + escapeHtml: this.refs.escapeHtmlExport.checked + } + } + + this.setState({ config: newConfig }, () => { + const { exports } = this.props.config + this.currentConfig = { exports } + if (_.isEqual(this.currentConfig, this.state.config)) { + this.props.haveToSave() + } else { + this.props.haveToSave({ + tab: 'EXPORT', + type: 'warning', + message: i18n.__('You have to save!') + }) + } + }) + } + + handleSaveUIClick (e) { + const newConfig = { + exports: this.state.config.exports + } + + ConfigManager.set(newConfig) + + store.dispatch({ + type: 'SET_UI', + config: newConfig + }) + this.clearMessage() + this.props.haveToSave() + } + + clearMessage () { + _.debounce(() => { + this.setState({ + UiAlert: null + }) + }, 2000)() + } + + render () { + const ExportAlert = this.state.ExportAlert + const ExportAlertElement = ExportAlert != null + ?

+ {ExportAlert.message} +

+ : null + return ( +
+
+
{i18n.__('Export')}
+ +
+ +
+
+ + {ExportAlertElement} +
+
+
+ ) + } +} + +export default CSSModules(Export, styles) diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index 70e25a88..a68cd588 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -7,6 +7,7 @@ import InfoTab from './InfoTab' import Crowdfunding from './Crowdfunding' import StoragesTab from './StoragesTab' import Blog from './Blog' +import Export from './Export' import ModalEscButton from 'browser/components/ModalEscButton' import CSSModules from 'browser/lib/CSSModules' import styles from './PreferencesModal.styl' @@ -86,6 +87,13 @@ class Preferences extends React.Component { haveToSave={alert => this.setState({BlogAlert: alert})} /> ) + case 'EXPORT': + return ( + this.setState({ExportAlert: alert})} + /> + ) case 'STORAGES': default: return ( @@ -123,7 +131,8 @@ class Preferences extends React.Component { {target: 'UI', label: i18n.__('Interface'), UI: this.state.UIAlert}, {target: 'INFO', label: i18n.__('About')}, {target: 'CROWDFUNDING', label: i18n.__('Crowdfunding')}, - {target: 'BLOG', label: i18n.__('Blog'), Blog: this.state.BlogAlert} + {target: 'BLOG', label: i18n.__('Blog'), Blog: this.state.BlogAlert}, + {target: 'EXPORT', label: i18n.__('Export')} ] const navButtons = tabs.map((tab) => { From 9893fd9ae55169498d1ee55fbf152b11322303ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Sat, 19 May 2018 19:52:47 +0700 Subject: [PATCH 03/75] fixed eslint --- browser/main/modals/PreferencesModal/Export.js | 2 +- browser/main/modals/PreferencesModal/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/main/modals/PreferencesModal/Export.js b/browser/main/modals/PreferencesModal/Export.js index ae57cc14..c7d99c8c 100644 --- a/browser/main/modals/PreferencesModal/Export.js +++ b/browser/main/modals/PreferencesModal/Export.js @@ -9,7 +9,7 @@ const electron = require('electron') const ipc = electron.ipcRenderer class Export extends React.Component { - constructor(props) { + constructor (props) { super(props) this.state = { config: props.config diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index a68cd588..02710289 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -89,7 +89,7 @@ class Preferences extends React.Component { ) case 'EXPORT': return ( - this.setState({ExportAlert: alert})} /> From 1516807ed548d95e031f4ff64506764fd9c50e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Sun, 20 May 2018 19:24:36 +0700 Subject: [PATCH 04/75] fixed double escape html --- browser/lib/utils.js | 43 ++++++------------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/browser/lib/utils.js b/browser/lib/utils.js index f67ca377..d27449e0 100644 --- a/browser/lib/utils.js +++ b/browser/lib/utils.js @@ -15,43 +15,12 @@ export function escapeHtmlCharacters (text) { return str } - let escape - let html = '' - let index = 0 - let lastIndex = 0 - - for (index = match.index; index < str.length; index++) { - switch (str.charCodeAt(index)) { - case 34: // " - escape = '"' - break - case 38: // & - escape = '&' - break - case 39: // ' - escape = ''' - break - case 60: // < - escape = '<' - break - case 62: // > - escape = '>' - break - default: - continue - } - - if (lastIndex !== index) { - html += str.substring(lastIndex, index) - } - - lastIndex = index + 1 - html += escape - } - - return lastIndex !== index - ? html + str.substring(lastIndex, index) - : html + return str + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, ''') } export default { From 707356bffe54a4d00c944b50330134930a90ceed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Tue, 29 May 2018 18:15:57 +0700 Subject: [PATCH 05/75] revert to the original function for better performance --- browser/lib/utils.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/browser/lib/utils.js b/browser/lib/utils.js index d27449e0..ee4d4ad0 100644 --- a/browser/lib/utils.js +++ b/browser/lib/utils.js @@ -15,12 +15,43 @@ export function escapeHtmlCharacters (text) { return str } - return str - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, ''') + let escape + let html = '' + let index = 0 + let lastIndex = 0 + + for (index = match.index; index < str.length; index++) { + switch (str.charCodeAt(index)) { + case 34: // " + escape = '"' + break + case 38: // & + escape = '&ssssss;' + break + case 39: // ' + escape = ''' + break + case 60: // < + escape = '<' + break + case 62: // > + escape = '>' + break + default: + continue + } + + if (lastIndex !== index) { + html += str.substring(lastIndex, index) + } + + lastIndex = index + 1 + html += escape + } + + return lastIndex !== index + ? html + str.substring(lastIndex, index) + : html } export default { From c6a9c9c57d73a5e84476d473a3b75f3efbdc1392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Tue, 5 Jun 2018 21:24:37 +0700 Subject: [PATCH 06/75] fixed disappear scrollbar --- browser/components/MarkdownPreview.js | 18 ++++++++++++++++++ browser/main/global.styl | 13 +++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 89f71a9b..7b5facf2 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -126,6 +126,21 @@ body p { ` } +const scrollBarStyle = ` +::-webkit-scrollbar-track { + border-radius: 10px; +} + +::-webkit-scrollbar { + width: 12px; +} + +::-webkit-scrollbar-thumb { + box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); + background-color: rgba(0, 0, 0, 0.3); +} +` + const { shell } = require('electron') const OSX = global.process.platform === 'darwin' @@ -298,6 +313,9 @@ export default class MarkdownPreview extends React.Component { + ` CSS_FILES.forEach((file) => { diff --git a/browser/main/global.styl b/browser/main/global.styl index 7025163f..c68df2b8 100644 --- a/browser/main/global.styl +++ b/browser/main/global.styl @@ -15,6 +15,16 @@ body font-weight 200 -webkit-font-smoothing antialiased +::-webkit-scrollbar-track + border-radius 10px + +::-webkit-scrollbar + width 12px + +::-webkit-scrollbar-thumb + box-shadow inset 0 0 6px rgba(0, 0, 0, 0.3) + background-color rgba(0, 0, 0, 0.3) + button, input, select, textarea font-family DEFAULT_FONTS @@ -85,7 +95,7 @@ modalBackColor = white absolute top left bottom right background-color modalBackColor z-index modalZIndex + 1 - + body[data-theme="dark"] .ModalBase @@ -140,4 +150,3 @@ body[data-theme="monokai"] background-color $ui-monokai-backgroundColor .sortableItemHelper color: $ui-monokai-text-color - From 31f1ebe801e9ffa5180934aff46fc68e654b9a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Tue, 5 Jun 2018 21:31:50 +0700 Subject: [PATCH 07/75] removed unnecessary style --- browser/components/MarkdownPreview.js | 4 ---- browser/main/global.styl | 3 --- 2 files changed, 7 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 7b5facf2..0348996d 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -127,10 +127,6 @@ body p { } const scrollBarStyle = ` -::-webkit-scrollbar-track { - border-radius: 10px; -} - ::-webkit-scrollbar { width: 12px; } diff --git a/browser/main/global.styl b/browser/main/global.styl index c68df2b8..9a967085 100644 --- a/browser/main/global.styl +++ b/browser/main/global.styl @@ -15,9 +15,6 @@ body font-weight 200 -webkit-font-smoothing antialiased -::-webkit-scrollbar-track - border-radius 10px - ::-webkit-scrollbar width 12px From 0ae1263d9deff16c25f849e9a438abd0e250e671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Wed, 6 Jun 2018 00:25:49 +0700 Subject: [PATCH 08/75] abort --- browser/components/MarkdownPreview.js | 2 +- browser/lib/markdown.js | 1 - browser/main/lib/ConfigManager.js | 3 - .../main/modals/PreferencesModal/Export.js | 120 ------------------ browser/main/modals/PreferencesModal/index.js | 11 +- 5 files changed, 2 insertions(+), 135 deletions(-) delete mode 100644 browser/main/modals/PreferencesModal/Export.js diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index ef11a0cc..04fc29fd 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -219,7 +219,7 @@ export default class MarkdownPreview extends React.Component { const {fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme} = this.getStyleParams() const inlineStyles = buildStyle(fontFamily, fontSize, codeBlockFontFamily, lineNumber, scrollPastEnd, theme) - let body = this.markdown.render(ConfigManager.get().exports.escapeHtml ? escapeHtmlCharacters(noteContent) : noteContent) + let body = this.markdown.render(escapeHtmlCharacters(noteContent)) const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES] const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(noteContent, this.props.storagePath) diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js index 5848aeea..2d81cd31 100644 --- a/browser/lib/markdown.js +++ b/browser/lib/markdown.js @@ -239,4 +239,3 @@ class Markdown { } export default Markdown - diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 5b263191..79fe0f5f 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -65,9 +65,6 @@ export const DEFAULT_CONFIG = { token: '', username: '', password: '' - }, - exports: { - escapeHtml: true } } diff --git a/browser/main/modals/PreferencesModal/Export.js b/browser/main/modals/PreferencesModal/Export.js deleted file mode 100644 index c7d99c8c..00000000 --- a/browser/main/modals/PreferencesModal/Export.js +++ /dev/null @@ -1,120 +0,0 @@ -import React from 'react' -import ConfigManager from 'browser/main/lib/ConfigManager' -import i18n from 'browser/lib/i18n' -import styles from './ConfigTab.styl' -import CSSModules from 'browser/lib/CSSModules' -import store from 'browser/main/store' - -const electron = require('electron') -const ipc = electron.ipcRenderer - -class Export extends React.Component { - constructor (props) { - super(props) - this.state = { - config: props.config - } - } - - componentDidMount () { - this.handleSettingDone = () => { - this.setState({ExportAlert: { - type: 'success', - message: i18n.__('Successfully applied!') - }}) - } - this.handleSettingError = (err) => { - this.setState({ExportAlert: { - type: 'error', - message: err.message != null ? err.message : i18n.__('Error occurs!') - }}) - } - ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) - ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) - } - - componentWillUnmount () { - ipc.removeListener('APP_SETTING_DONE', this.handleSettingDone) - ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError) - } - - handleUIChange (e) { - const newConfig = { - exports: { - escapeHtml: this.refs.escapeHtmlExport.checked - } - } - - this.setState({ config: newConfig }, () => { - const { exports } = this.props.config - this.currentConfig = { exports } - if (_.isEqual(this.currentConfig, this.state.config)) { - this.props.haveToSave() - } else { - this.props.haveToSave({ - tab: 'EXPORT', - type: 'warning', - message: i18n.__('You have to save!') - }) - } - }) - } - - handleSaveUIClick (e) { - const newConfig = { - exports: this.state.config.exports - } - - ConfigManager.set(newConfig) - - store.dispatch({ - type: 'SET_UI', - config: newConfig - }) - this.clearMessage() - this.props.haveToSave() - } - - clearMessage () { - _.debounce(() => { - this.setState({ - UiAlert: null - }) - }, 2000)() - } - - render () { - const ExportAlert = this.state.ExportAlert - const ExportAlertElement = ExportAlert != null - ?

- {ExportAlert.message} -

- : null - return ( -
-
-
{i18n.__('Export')}
- -
- -
-
- - {ExportAlertElement} -
-
-
- ) - } -} - -export default CSSModules(Export, styles) diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index 02710289..70e25a88 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -7,7 +7,6 @@ import InfoTab from './InfoTab' import Crowdfunding from './Crowdfunding' import StoragesTab from './StoragesTab' import Blog from './Blog' -import Export from './Export' import ModalEscButton from 'browser/components/ModalEscButton' import CSSModules from 'browser/lib/CSSModules' import styles from './PreferencesModal.styl' @@ -87,13 +86,6 @@ class Preferences extends React.Component { haveToSave={alert => this.setState({BlogAlert: alert})} /> ) - case 'EXPORT': - return ( - this.setState({ExportAlert: alert})} - /> - ) case 'STORAGES': default: return ( @@ -131,8 +123,7 @@ class Preferences extends React.Component { {target: 'UI', label: i18n.__('Interface'), UI: this.state.UIAlert}, {target: 'INFO', label: i18n.__('About')}, {target: 'CROWDFUNDING', label: i18n.__('Crowdfunding')}, - {target: 'BLOG', label: i18n.__('Blog'), Blog: this.state.BlogAlert}, - {target: 'EXPORT', label: i18n.__('Export')} + {target: 'BLOG', label: i18n.__('Blog'), Blog: this.state.BlogAlert} ] const navButtons = tabs.map((tab) => { From 8dbf4563980925930c70ea7a4c2b952f6239106f Mon Sep 17 00:00:00 2001 From: Jannick Hemelhof Date: Sat, 9 Jun 2018 08:52:46 +0200 Subject: [PATCH 09/75] Upgrade to Electron v2.0.2 --- lib/main-window.js | 2 +- lib/main.html | 2 +- package.json | 2 +- yarn.lock | 7 ++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/main-window.js b/lib/main-window.js index 86b85a24..a6d129fc 100644 --- a/lib/main-window.js +++ b/lib/main-window.js @@ -17,7 +17,7 @@ const mainWindow = new BrowserWindow({ autoHideMenuBar: showMenu, webPreferences: { zoomFactor: 1.0, - blinkFeatures: 'OverlayScrollbars' + enableBlinkFeatures: 'OverlayScrollbars' }, icon: path.resolve(__dirname, '../resources/app.png') }) diff --git a/lib/main.html b/lib/main.html index 15e2bbeb..22527d99 100644 --- a/lib/main.html +++ b/lib/main.html @@ -115,7 +115,7 @@