From 46ac4e72091d5f0cb7ed513e7c14a95fe142c06b Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Thu, 30 May 2019 09:09:44 +0200 Subject: [PATCH 1/6] change process.env check --- browser/main/DevTools/index.js | 6 +++--- browser/main/store.js | 5 +++-- lib/main-window.js | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/browser/main/DevTools/index.js b/browser/main/DevTools/index.js index 93d666a24..d39d5fbbe 100644 --- a/browser/main/DevTools/index.js +++ b/browser/main/DevTools/index.js @@ -1,8 +1,8 @@ /* eslint-disable no-undef */ -if (process.env.NODE_ENV === 'production') { +if (process.env.NODE_ENV === 'development') { // eslint-disable-next-line global-require - module.exports = require('./index.prod').default + module.exports = require('./index.dev').default } else { // eslint-disable-next-line global-require - module.exports = require('./index.dev').default + module.exports = require('./index.prod').default } diff --git a/browser/main/store.js b/browser/main/store.js index c708c3ad8..d48198a79 100644 --- a/browser/main/store.js +++ b/browser/main/store.js @@ -476,7 +476,8 @@ const reducer = combineReducers({ router: connectRouter(history) }) -const store = createStore(reducer, undefined, compose( - applyMiddleware(routerMiddleware(history)), DevTools.instrument())) +const store = createStore(reducer, undefined, process.env.NODE_ENV === 'development' + ? compose(applyMiddleware(routerMiddleware(history)), DevTools.instrument()) + : applyMiddleware(routerMiddleware(history))) export { store, history } diff --git a/lib/main-window.js b/lib/main-window.js index e650cb922..515dc8b45 100644 --- a/lib/main-window.js +++ b/lib/main-window.js @@ -54,7 +54,7 @@ const mainWindow = new BrowserWindow({ }, icon: path.resolve(__dirname, '../resources/app.png') }) -const url = path.resolve(__dirname, process.env.NODE_ENV === 'production' ? './main.production.html' : './main.development.html') +const url = path.resolve(__dirname, process.env.NODE_ENV === 'development' ? './main.development.html' : './main.production.html') mainWindow.loadURL('file://' + url) mainWindow.setMenuBarVisibility(false) From 8888a2fa35d41f38ca8974a00ba0804de508f4aa Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Thu, 30 May 2019 09:13:29 +0200 Subject: [PATCH 2/6] change theme path usage and remove relative path --- browser/components/MarkdownPreview.js | 6 +----- browser/main/lib/ConfigManager.js | 5 ++--- browser/main/modals/PreferencesModal/UiTab.js | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index bb663c5e3..b21914786 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -673,11 +673,7 @@ export default class MarkdownPreview extends React.Component { GetCodeThemeLink (name) { const theme = consts.THEMES.find(theme => theme.name === name) - if (theme) { - return `${appPath}/${theme.path}` - } else { - return `${appPath}/node_modules/codemirror/theme/elegant.css` - } + return theme ? theme.path : `${appPath}/node_modules/codemirror/theme/elegant.css` } rewriteIframe () { diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index bea019fa9..516a3e173 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -108,7 +108,6 @@ function validate (config) { } function _save (config) { - console.log(config) window.localStorage.setItem('config', JSON.stringify(config)) } @@ -141,7 +140,7 @@ function get () { const theme = consts.THEMES.find(theme => theme.name === config.editor.theme) if (theme) { - editorTheme.setAttribute('href', `../${theme.path}`) + editorTheme.setAttribute('href', theme.path) } else { config.editor.theme = 'default' } @@ -183,7 +182,7 @@ function set (updates) { const newTheme = consts.THEMES.find(theme => theme.name === newConfig.editor.theme) if (newTheme) { - editorTheme.setAttribute('href', `../${newTheme.path}`) + editorTheme.setAttribute('href', newTheme.path) } ipcRenderer.send('config-renew', { diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index f74dbda52..ae5162dfa 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -135,7 +135,7 @@ class UiTab extends React.Component { const theme = consts.THEMES.find(theme => theme.name === newCodemirrorTheme) if (theme) { - checkHighLight.setAttribute('href', `../${theme.path}`) + checkHighLight.setAttribute('href', theme.path) } } From 0ac91249be64aa3caa4840eb4957a4fb7c281899 Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Thu, 30 May 2019 09:31:56 +0200 Subject: [PATCH 3/6] fix test for Windows (fs.rmdir throws dir not empty error) --- tests/dataApi/copyFile-test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/dataApi/copyFile-test.js b/tests/dataApi/copyFile-test.js index 412d510a0..533b13543 100644 --- a/tests/dataApi/copyFile-test.js +++ b/tests/dataApi/copyFile-test.js @@ -3,6 +3,9 @@ const copyFile = require('browser/main/lib/dataApi/copyFile') const path = require('path') const fs = require('fs') +const os = require('os') +const execSync = require('child_process').execSync +const removeDirCommand = os.platform() === 'win32' ? 'rmdir /s /q ' : 'rm -rf ' const testFile = 'test.txt' const srcFolder = path.join(__dirname, '🤔') @@ -29,7 +32,7 @@ test('`copyFile` should handle encoded URI on src path', (t) => { test.after((t) => { fs.unlinkSync(srcPath) fs.unlinkSync(dstPath) - fs.rmdirSync(srcFolder) - fs.rmdirSync(dstFolder) + execSync(removeDirCommand + '"' + srcFolder + '"') + execSync(removeDirCommand + '"' + dstFolder + '"') }) From 1e3d6608c200c6832989d8199df44eede747750b Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Thu, 30 May 2019 09:10:04 -0700 Subject: [PATCH 4/6] fix path Linux --- browser/components/MarkdownPreview.js | 5 ++++- browser/lib/consts.js | 7 +++++-- browser/main/lib/ConfigManager.js | 4 ++-- browser/main/modals/PreferencesModal/UiTab.js | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index b21914786..6bc50ca95 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -45,6 +45,7 @@ const CSS_FILES = [ `${appPath}/node_modules/codemirror/lib/codemirror.css`, `${appPath}/node_modules/react-image-carousel/lib/css/main.min.css` ] +const win = global.process.platform === 'win32' function buildStyle ( fontFamily, @@ -673,7 +674,9 @@ export default class MarkdownPreview extends React.Component { GetCodeThemeLink (name) { const theme = consts.THEMES.find(theme => theme.name === name) - return theme ? theme.path : `${appPath}/node_modules/codemirror/theme/elegant.css` + return theme + ? (win ? theme.path : `../${theme.path}`) + : `${appPath}/node_modules/codemirror/theme/elegant.css` } rewriteIframe () { diff --git a/browser/lib/consts.js b/browser/lib/consts.js index 9c9930551..eeff397bb 100644 --- a/browser/lib/consts.js +++ b/browser/lib/consts.js @@ -7,9 +7,12 @@ const CODEMIRROR_THEME_PATH = 'node_modules/codemirror/theme' const CODEMIRROR_EXTRA_THEME_PATH = 'extra_scripts/codemirror/theme' const isProduction = process.env.NODE_ENV === 'production' +const exePath = path.dirname(app.getPath('exe')) +const appPath = path.join(exePath, 'resources', 'app') + const paths = [ - isProduction ? path.join(app.getAppPath(), CODEMIRROR_THEME_PATH) : path.resolve(CODEMIRROR_THEME_PATH), - isProduction ? path.join(app.getAppPath(), CODEMIRROR_EXTRA_THEME_PATH) : path.resolve(CODEMIRROR_EXTRA_THEME_PATH) + isProduction ? path.join(appPath, CODEMIRROR_THEME_PATH) : path.resolve(CODEMIRROR_THEME_PATH), + isProduction ? path.join(appPath, CODEMIRROR_EXTRA_THEME_PATH) : path.resolve(CODEMIRROR_EXTRA_THEME_PATH) ] const themes = paths diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 516a3e173..78ea93883 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -140,7 +140,7 @@ function get () { const theme = consts.THEMES.find(theme => theme.name === config.editor.theme) if (theme) { - editorTheme.setAttribute('href', theme.path) + editorTheme.setAttribute('href', win ? theme.path : `../${theme.path}`) } else { config.editor.theme = 'default' } @@ -182,7 +182,7 @@ function set (updates) { const newTheme = consts.THEMES.find(theme => theme.name === newConfig.editor.theme) if (newTheme) { - editorTheme.setAttribute('href', newTheme.path) + editorTheme.setAttribute('href', win ? newTheme.path : `../${newTheme.path}`) } ipcRenderer.send('config-renew', { diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index ae5162dfa..91a257721 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -14,6 +14,7 @@ import { getLanguages } from 'browser/lib/Languages' import normalizeEditorFontFamily from 'browser/lib/normalizeEditorFontFamily' const OSX = global.process.platform === 'darwin' +const win = global.process.platform === 'win32' const electron = require('electron') const ipc = electron.ipcRenderer @@ -135,7 +136,7 @@ class UiTab extends React.Component { const theme = consts.THEMES.find(theme => theme.name === newCodemirrorTheme) if (theme) { - checkHighLight.setAttribute('href', theme.path) + checkHighLight.setAttribute('href', win ? theme.path : `../${theme.path}`) } } From e63dbca24653e0afa179d58b1f503a0021823fb8 Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Thu, 30 May 2019 09:36:48 -0700 Subject: [PATCH 5/6] fix app path --- browser/lib/consts.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/browser/lib/consts.js b/browser/lib/consts.js index eeff397bb..3603c202a 100644 --- a/browser/lib/consts.js +++ b/browser/lib/consts.js @@ -7,12 +7,10 @@ const CODEMIRROR_THEME_PATH = 'node_modules/codemirror/theme' const CODEMIRROR_EXTRA_THEME_PATH = 'extra_scripts/codemirror/theme' const isProduction = process.env.NODE_ENV === 'production' -const exePath = path.dirname(app.getPath('exe')) -const appPath = path.join(exePath, 'resources', 'app') const paths = [ - isProduction ? path.join(appPath, CODEMIRROR_THEME_PATH) : path.resolve(CODEMIRROR_THEME_PATH), - isProduction ? path.join(appPath, CODEMIRROR_EXTRA_THEME_PATH) : path.resolve(CODEMIRROR_EXTRA_THEME_PATH) + isProduction ? path.join(app.getAppPath(), CODEMIRROR_THEME_PATH) : path.resolve(CODEMIRROR_THEME_PATH), + isProduction ? path.join(app.getAppPath(), CODEMIRROR_EXTRA_THEME_PATH) : path.resolve(CODEMIRROR_EXTRA_THEME_PATH) ] const themes = paths From 57f7299ea3074626d490fcfb53571399ff0dca7b Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Fri, 31 May 2019 01:40:15 -0700 Subject: [PATCH 6/6] path fix for MacOs --- browser/components/MarkdownPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 6bc50ca95..85b92b4da 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -675,7 +675,7 @@ export default class MarkdownPreview extends React.Component { const theme = consts.THEMES.find(theme => theme.name === name) return theme - ? (win ? theme.path : `../${theme.path}`) + ? (win ? theme.path : `${appPath}/${theme.path}`) : `${appPath}/node_modules/codemirror/theme/elegant.css` }