2017-10-24 00:11:48 +02:00
|
|
|
import {getAccentableIcons} from '../../helpers/fs';
|
2017-06-17 16:52:27 +02:00
|
|
|
import * as fs from 'fs';
|
|
|
|
|
2017-06-20 14:39:45 +02:00
|
|
|
import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute } from "../../helpers/fs";
|
2017-07-21 20:20:17 +02:00
|
|
|
import { getCurrentThemeIconsID } from "../../helpers/vscode";
|
|
|
|
import { getCustomSettings, isAccent, isMaterialThemeIcons } from "../../helpers/settings";
|
2017-06-17 16:52:27 +02:00
|
|
|
|
|
|
|
import { CHARSET } from "../../consts/files";
|
|
|
|
import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
|
|
|
|
import { IThemeIcons } from "../../interfaces/itheme-icons";
|
|
|
|
|
2017-10-24 00:11:48 +02:00
|
|
|
function replaceIconPathWithAccent(iconPath: string, accentName: string): string {
|
|
|
|
return iconPath.replace('.svg', `.accent.${ accentName }.svg`);
|
|
|
|
}
|
|
|
|
|
2017-07-21 20:20:17 +02:00
|
|
|
export const THEME_ICONS = () => {
|
|
|
|
let deferred: any = {};
|
|
|
|
let promise = new Promise((resolve, reject) => {
|
|
|
|
deferred.resolve = resolve;
|
|
|
|
deferred.reject = reject;
|
|
|
|
});
|
|
|
|
let themeIconsID: string = getCurrentThemeIconsID();
|
|
|
|
|
|
|
|
if (isMaterialThemeIcons(themeIconsID)) {
|
|
|
|
let customSettings = getCustomSettings();
|
|
|
|
let defaults = getDefaultValues();
|
|
|
|
let accentName = customSettings.accent;
|
|
|
|
let variantName: string = customSettings.themeColours === undefined ? '' : customSettings.themeColours;
|
|
|
|
let themeContribute: IPackageJSONThemeIcons = getThemeIconsContribute(themeIconsID);
|
|
|
|
let theme: IThemeIcons = getThemeIconsByContributeID(themeIconsID);
|
|
|
|
let themepath: string = getAbsolutePath(themeContribute.path);
|
|
|
|
|
|
|
|
if (isAccent(accentName, defaults)) {
|
|
|
|
let _accentName = accentName.replace(/\s+/, '-');
|
2017-10-24 00:11:48 +02:00
|
|
|
|
|
|
|
getAccentableIcons().forEach(iconname => {
|
|
|
|
let distIcon = (theme.iconDefinitions as any)[iconname];
|
|
|
|
let outIcon = (defaults.icons.theme.iconDefinitions as any)[iconname];
|
|
|
|
|
|
|
|
if (typeof distIcon === 'object' && typeof outIcon === 'object') {
|
|
|
|
distIcon.iconPath = replaceIconPathWithAccent(outIcon.iconPath, _accentName)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath.replace('.svg', `.accent.${ _accentName }.svg`);
|
|
|
|
// theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath.replace('.svg', `.accent.${ _accentName }.svg`);
|
2017-07-21 20:20:17 +02:00
|
|
|
} else {
|
2017-10-24 00:11:48 +02:00
|
|
|
|
|
|
|
getAccentableIcons().forEach(iconname => {
|
|
|
|
let distIcon = (theme.iconDefinitions as any)[iconname];
|
|
|
|
let outIcon = (defaults.icons.theme.iconDefinitions as any)[iconname];
|
|
|
|
|
|
|
|
distIcon.iconPath = outIcon.iconPath;
|
|
|
|
});
|
|
|
|
// theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath;
|
|
|
|
// theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath;
|
2017-07-21 20:20:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
theme.iconDefinitions._folder_dark.iconPath = defaults.icons.theme.iconDefinitions._folder_dark.iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
theme.iconDefinitions._folder_dark_build.iconPath = defaults.icons.theme.iconDefinitions._folder_dark_build.iconPath.replace('.svg', `${ variantName }.svg`);
|
2017-10-24 00:11:48 +02:00
|
|
|
// theme.iconDefinitions._file_folder.iconPath = defaults.icons.theme.iconDefinitions._file_folder.iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
// theme.iconDefinitions["_file_folder-build"].iconPath = defaults.icons.theme.iconDefinitions["_file_folder-build"].iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
theme.iconDefinitions._folder_light.iconPath = defaults.icons.theme.iconDefinitions._folder_light.iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
theme.iconDefinitions["_folder_light_build"].iconPath = defaults.icons.theme.iconDefinitions["_folder_light_build"].iconPath.replace('.svg', `${ variantName }.svg`);
|
2017-07-21 20:20:17 +02:00
|
|
|
|
|
|
|
fs.writeFile(themepath, JSON.stringify(theme), { encoding: CHARSET }, (error) => {
|
|
|
|
if (error) {
|
|
|
|
deferred.reject(error);
|
|
|
|
return;
|
2017-06-23 13:55:52 +02:00
|
|
|
}
|
2017-06-17 16:52:27 +02:00
|
|
|
|
2017-07-21 20:20:17 +02:00
|
|
|
deferred.resolve();
|
|
|
|
});
|
|
|
|
} else {
|
2017-07-24 11:05:15 +02:00
|
|
|
deferred.resolve();
|
2017-07-21 20:20:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return promise;
|
2017-06-17 16:52:27 +02:00
|
|
|
}
|