From 92fd7ac09c5897b04689dd23f51b3e0226404e45 Mon Sep 17 00:00:00 2001 From: Dick Choi Date: Tue, 4 Oct 2016 11:07:21 +0900 Subject: [PATCH] use default theme if theme doesn't exist --- browser/finder/ipcClient.js | 6 ++++++ browser/lib/consts.js | 2 +- browser/main/lib/ConfigManager.js | 14 +++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/browser/finder/ipcClient.js b/browser/finder/ipcClient.js index 9067aa8d..6a5fb929 100644 --- a/browser/finder/ipcClient.js +++ b/browser/finder/ipcClient.js @@ -3,6 +3,7 @@ const { remote, ipcRenderer } = require('electron') const { app, Menu } = remote const path = require('path') const store = require('./store') +const consts = require('browser/lib/consts') nodeIpc.config.id = 'finder' nodeIpc.config.retry = 1500 @@ -94,6 +95,11 @@ nodeIpc.connectTo( editorTheme.setAttribute('rel', 'stylesheet') document.head.appendChild(editorTheme) } + + config.editor.theme = consts.THEMES.some((theme) => theme === config.editor.theme) + ? config.editor.theme + : 'default' + if (config.editor.theme !== 'default') { editorTheme.setAttribute('href', '../node_modules/codemirror/theme/' + config.editor.theme + '.css') } diff --git a/browser/lib/consts.js b/browser/lib/consts.js index 4241e2db..253bc974 100644 --- a/browser/lib/consts.js +++ b/browser/lib/consts.js @@ -30,7 +30,7 @@ const consts = { 'Dodger Blue', 'Violet Eggplant' ], - THEMES: themes + THEMES: ['default'].concat(themes) } module.exports = consts diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 4cd96190..62cd5aae 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -3,6 +3,7 @@ import _ from 'lodash' const OSX = global.process.platform === 'darwin' const electron = require('electron') const { ipcRenderer } = electron +const consts = require('browser/lib/consts') let isInitialized = false @@ -75,6 +76,11 @@ function get () { editorTheme.setAttribute('rel', 'stylesheet') document.head.appendChild(editorTheme) } + + config.editor.theme = consts.THEMES.some((theme) => theme === config.editor.theme) + ? config.editor.theme + : 'default' + if (config.editor.theme !== 'default') { editorTheme.setAttribute('href', '../node_modules/codemirror/theme/' + config.editor.theme + '.css') } @@ -102,7 +108,13 @@ function set (updates) { editorTheme.setAttribute('rel', 'stylesheet') document.head.appendChild(editorTheme) } - editorTheme.setAttribute('href', '../node_modules/codemirror/theme/' + newConfig.editor.theme + '.css') + let newTheme = consts.THEMES.some((theme) => theme === newConfig.editor.theme) + ? newConfig.editor.theme + : 'default' + + if (newTheme !== 'default') { + editorTheme.setAttribute('href', '../node_modules/codemirror/theme/' + newTheme + '.css') + } ipcRenderer.send('config-renew', { config: get()