From a9bb9b697bc1c287e532794d921970679267c0d0 Mon Sep 17 00:00:00 2001 From: CHaBou Date: Sun, 10 Sep 2017 11:35:39 +0200 Subject: [PATCH] Add depreaction warning for hterm css * Notify user when its config conatins deprecated CSS classes * Add warning in devtools console about plugins using deprecated classes --- app/config.js | 32 ++++++++++++++++++++++++++++++++ app/plugins.js | 18 ++++++++++++++++++ lib/utils/plugins.js | 8 ++++++++ 3 files changed, 58 insertions(+) diff --git a/app/config.js b/app/config.js index 6a7c613b..78fd1215 100644 --- a/app/config.js +++ b/app/config.js @@ -23,6 +23,7 @@ const _watch = function () { cfg = _import(); notify('Configuration updated', 'Hyper configuration reloaded!'); watchers.forEach(fn => fn()); + checkDeprecatedConfig() }); _watcher.on('error', error => { @@ -70,7 +71,38 @@ exports.extendKeymaps = function (keymaps) { exports.setup = function () { cfg = _import(); _watch(); + checkDeprecatedConfig() }; exports.getWin = win.get; exports.winRecord = win.recordState; + +const getDeprecatedCSS = function (config) { + const deprecated = []; + const deprecatedCSS = [ + 'x-screen', + 'x-row', + 'cursor-node', + '::selection' + ]; + deprecatedCSS.forEach(css => { + if ((config.css && config.css.indexOf(css) !== -1) || + (config.termCSS && config.termCSS.indexOf(css) !== -1)) { + deprecated.push(css); + } + }) + return deprecated; +} +exports.getDeprecatedCSS = getDeprecatedCSS; + +const checkDeprecatedConfig = function () { + if (!cfg.config) { + return; + } + const deprecated = getDeprecatedCSS(cfg.config); + if (deprecated.length === 0) { + return; + } + const deprecatedStr = deprecated.join(', '); + notify('Configuration warning', `Your configuration uses some deprecated CSS classes (${deprecatedStr})`) +} diff --git a/app/plugins.js b/app/plugins.js index 10d57cc5..e503d1f1 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -304,6 +304,24 @@ exports.extendKeymaps = function () { }); }; +exports.getDeprecatedConfig = () => { + const deprecated = {}; + const baseConfig = config.getConfig(); + modules.forEach(plugin => { + if (!plugin.decorateConfig) { + return; + } + // We need to clone config in case of plugin modifies config directly. + const configTmp = plugin.decorateConfig(JSON.parse(JSON.stringify(baseConfig))); + const pluginCSSDeprecated = config.getDeprecatedCSS(configTmp); + if (pluginCSSDeprecated.length === 0) { + return; + } + deprecated[plugin._name] = {css: pluginCSSDeprecated}; + }) + return deprecated; +} + exports.decorateMenu = function (tpl) { return decorateObject(tpl, 'decorateMenu'); }; diff --git a/lib/utils/plugins.js b/lib/utils/plugins.js index b9912e88..98fc86ff 100644 --- a/lib/utils/plugins.js +++ b/lib/utils/plugins.js @@ -228,6 +228,14 @@ const loadModules = () => { return mod; }) .filter(mod => Boolean(mod)); + + const deprecatedPlugins = plugins.getDeprecatedConfig(); + Object.keys(deprecatedPlugins).forEach(name => { + const { css } = deprecatedPlugins[name]; + if (css) { + console.warn(`Warning: "${name}" plugin uses some deprecated CSS classes (${css.join(', ')}).`); + } + }); }; // load modules for initial decoration