feat: wrap accent settings inside variant name (#504)

This commit is contained in:
Alessio Occhipinti 2020-09-10 21:38:44 +02:00 committed by GitHub
parent 58d80a8df6
commit 596b6e68a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 9 deletions

View file

@ -38,17 +38,30 @@ const quickPick = async (): Promise<string> => {
}; };
export const command = async (): Promise<void> => { export const command = async (): Promise<void> => {
const pkg = extensionManager.getPackageJSON();
const currentThemeID = workspace.getConfiguration().get<string>('workbench.colorTheme');
const isMaterialTheme = Boolean(pkg.contributes.themes.find(theme => theme.label === currentThemeID));
if (!isMaterialTheme) {
return;
}
const themeConfig = extensionManager.getConfig(); const themeConfig = extensionManager.getConfig();
const currentColorCustomizationsConfig: any = workspace.getConfiguration().get('workbench.colorCustomizations'); const currentColorCustomizationsConfig: any = workspace.getConfiguration().get('workbench.colorCustomizations');
const accent = await quickPick(); const accent = await quickPick();
let config = {};
const config = accent === PURGE_KEY ? { if (accent === PURGE_KEY) {
...currentColorCustomizationsConfig, const {[currentThemeID]: _, ...rest} = currentColorCustomizationsConfig;
...getThemeColorCustomizationsConfig() config = rest;
} : { } else {
config = {
...currentColorCustomizationsConfig, ...currentColorCustomizationsConfig,
[`[${currentThemeID}]`]: {
...getThemeColorCustomizationsConfig(themeConfig.accents[accent]) ...getThemeColorCustomizationsConfig(themeConfig.accents[accent])
}
}; };
}
await updateColorCustomizationsConfig(config); await updateColorCustomizationsConfig(config);
await settingsManager.updateSetting('accent', accent); await settingsManager.updateSetting('accent', accent);

View file

@ -8,6 +8,15 @@ type MaterialThemeConfig = {
changelog?: { lastversion?: string }; changelog?: { lastversion?: string };
}; };
type PackageJSON = {
version: string;
contributes: {
themes: Array<{
label: string;
}>;
};
};
type InstallationType = { type InstallationType = {
firstInstall: boolean; firstInstall: boolean;
update: boolean; update: boolean;
@ -15,7 +24,7 @@ type InstallationType = {
export interface IExtensionManager { export interface IExtensionManager {
init: () => Promise<void>; init: () => Promise<void>;
getPackageJSON: () => Record<string, any>; getPackageJSON: () => PackageJSON;
getConfig: () => MaterialThemeConfig; getConfig: () => MaterialThemeConfig;
getInstallationType: () => Record<string, unknown>; getInstallationType: () => Record<string, unknown>;
updateConfig: (config: Partial<MaterialThemeConfig>) => Promise<void>; updateConfig: (config: Partial<MaterialThemeConfig>) => Promise<void>;
@ -33,7 +42,7 @@ class ExtensionManager implements IExtensionManager {
this.userConfigFileUri = extensionFolderUri.with({path: posix.join(extensionFolderUri.path, USER_CONFIG_FILE_NAME)}); this.userConfigFileUri = extensionFolderUri.with({path: posix.join(extensionFolderUri.path, USER_CONFIG_FILE_NAME)});
} }
getPackageJSON(): Record<string, any> { getPackageJSON(): PackageJSON {
return extensions.getExtension(MATERIAL_THEME_EXT_ID).packageJSON; return extensions.getExtension(MATERIAL_THEME_EXT_ID).packageJSON;
} }