Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix theme path issue #3048

Merged
merged 6 commits into from Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions browser/components/MarkdownPreview.js
Expand Up @@ -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,
Expand Down Expand Up @@ -673,11 +674,9 @@ 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
? (win ? theme.path : `${appPath}/${theme.path}`)
: `${appPath}/node_modules/codemirror/theme/elegant.css`
}

rewriteIframe () {
Expand Down
1 change: 1 addition & 0 deletions browser/lib/consts.js
Expand Up @@ -7,6 +7,7 @@ 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 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)
Expand Down
6 changes: 3 additions & 3 deletions 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
}
5 changes: 2 additions & 3 deletions browser/main/lib/ConfigManager.js
Expand Up @@ -108,7 +108,6 @@ function validate (config) {
}

function _save (config) {
console.log(config)
window.localStorage.setItem('config', JSON.stringify(config))
}

Expand Down Expand Up @@ -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', win ? theme.path : `../${theme.path}`)
Copy link
Contributor Author

@AWolf81 AWolf81 May 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@incredibleweirdo Is this working on Mac? Just wondering because if the other change in MarkdownPreview was required then we should change every occurence from ../ to the absolute path.
But if it's working we can also keep it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, changing themes appears to work fine.

} else {
config.editor.theme = 'default'
}
Expand Down Expand Up @@ -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', win ? newTheme.path : `../${newTheme.path}`)
}

ipcRenderer.send('config-renew', {
Expand Down
3 changes: 2 additions & 1 deletion browser/main/modals/PreferencesModal/UiTab.js
Expand Up @@ -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
Expand Down Expand Up @@ -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}`)
}
}

Expand Down
5 changes: 3 additions & 2 deletions browser/main/store.js
Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion lib/main-window.js
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions tests/dataApi/copyFile-test.js
Expand Up @@ -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, '🤔')
Expand All @@ -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 + '"')
})