From 00c85e736c4f323a9d426391d75700fc37b7edee Mon Sep 17 00:00:00 2001 From: Alessio Occhipinti Date: Sat, 21 Apr 2018 13:57:08 +0200 Subject: [PATCH] Fix/adapt icons command (#162) * fix(adapt-icons): added new interface and method for vsc conf theme * fix(adapt-icons): getting theme name from vsc theme settings * chore(cleanup): removed useless interface property * chore(cleanup): temporary commented on useless script (for build sake) * chore(postintall): fixing tsc build after first install (for gulp sake) --- extensions/commands/theme-icons/index.ts | 17 +++++++++++++++-- extensions/commands/theme-variant/index.ts | 2 +- extensions/helpers/settings.ts | 10 ++++++++++ .../interfaces/itheme-custom-properties.ts | 1 - extensions/interfaces/itheme-settings.ts | 3 +++ package.json | 2 +- 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 extensions/interfaces/itheme-settings.ts diff --git a/extensions/commands/theme-icons/index.ts b/extensions/commands/theme-icons/index.ts index 057dafe..3d42bbc 100644 --- a/extensions/commands/theme-icons/index.ts +++ b/extensions/commands/theme-icons/index.ts @@ -3,7 +3,7 @@ import * as fs from 'fs'; import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute, getVariantIcons } from "../../helpers/fs"; import { getCurrentThemeIconsID } from "../../helpers/vscode"; -import { getCustomSettings, isAccent, isMaterialThemeIcons } from "../../helpers/settings"; +import { isAccent, isMaterialThemeIcons, getThemeSettings, getCustomSettings } from "../../helpers/settings"; import { CHARSET } from "../../consts/files"; import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json"; @@ -24,6 +24,17 @@ function replaceIconPathWithAccent(iconPath: string, accentName: string): string return iconPath.replace('.svg', `.accent.${ accentName }.svg`); } +function getVariantFromColor(color: string): string { + switch (color) { + case undefined || 'Material Theme': + return 'Default'; + case 'Material Theme High Contrast': + return 'Default High Contrast'; + default: + return color.replace(/Material Theme /gi, ''); + } +} + export const THEME_ICONS = () => { let deferred: any = {}; let promise = new Promise((resolve, reject) => { @@ -33,10 +44,12 @@ export const THEME_ICONS = () => { let themeIconsID: string = getCurrentThemeIconsID(); if (isMaterialThemeIcons(themeIconsID)) { + let themeSettings = getThemeSettings(); let customSettings = getCustomSettings(); let defaults = getDefaultValues(); let accentName = customSettings.accent; - let variantName: string = customSettings.themeColours === undefined ? '' : customSettings.themeColours; + let variantName: string = getVariantFromColor(themeSettings.colorTheme); + let themeContribute: IPackageJSONThemeIcons = getThemeIconsContribute(themeIconsID); let theme: IThemeIcons = getThemeIconsByContributeID(themeIconsID); let themepath: string = getAbsolutePath(themeContribute.path); diff --git a/extensions/commands/theme-variant/index.ts b/extensions/commands/theme-variant/index.ts index 08aaa4f..b84ea32 100644 --- a/extensions/commands/theme-variant/index.ts +++ b/extensions/commands/theme-variant/index.ts @@ -22,7 +22,7 @@ export const THEME_VARIANT = () => { let themepath: string = defaults.themeVariants[response]; let themeUITheme: string = defaults.themeVariantsUITheme[response]; - customSettings.themeColours = response; + // customSettings.themeColours = response; packageJSON.contributes.themes[0].path = themepath; packageJSON.contributes.themes[0].uiTheme = themeUITheme; diff --git a/extensions/helpers/settings.ts b/extensions/helpers/settings.ts index 0216fc2..3c8bb67 100644 --- a/extensions/helpers/settings.ts +++ b/extensions/helpers/settings.ts @@ -2,8 +2,18 @@ import * as vscode from 'vscode'; import { IDefaults } from "../interfaces/idefaults"; import { IThemeCustomProperties } from "../interfaces/itheme-custom-properties"; +import { IThemeSettings } from "../interfaces/itheme-settings"; import {getPackageJSON} from './fs'; +/** + * Gets theme settings + * @export + * @returns {*} + */ +export function getThemeSettings(): IThemeSettings { + return vscode.workspace.getConfiguration().get('workbench', {}); +} + /** * Gets saved accent * @export diff --git a/extensions/interfaces/itheme-custom-properties.ts b/extensions/interfaces/itheme-custom-properties.ts index bb084c4..3bd1bc2 100644 --- a/extensions/interfaces/itheme-custom-properties.ts +++ b/extensions/interfaces/itheme-custom-properties.ts @@ -1,5 +1,4 @@ export interface IThemeCustomProperties { accent?: string; accentPrevious?: string; - themeColours?: string; } \ No newline at end of file diff --git a/extensions/interfaces/itheme-settings.ts b/extensions/interfaces/itheme-settings.ts new file mode 100644 index 0000000..9e4f6bc --- /dev/null +++ b/extensions/interfaces/itheme-settings.ts @@ -0,0 +1,3 @@ +export interface IThemeSettings { + colorTheme?: string; +} \ No newline at end of file diff --git a/package.json b/package.json index e56e22c..913b6ee 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "build-icons-variants": "yarn gulp build:icons.variants", "build-themes": "yarn gulp build:themes", "release": "standard-version", - "postinstall": "node ./node_modules/vscode/bin/install && opencollective postinstall" + "postinstall": "node ./node_modules/vscode/bin/install && opencollective postinstall && tsc -p tsconfig.json" }, "categories": [ "Themes",