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> => {
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 currentColorCustomizationsConfig: any = workspace.getConfiguration().get('workbench.colorCustomizations');
const accent = await quickPick();
let config = {};
const config = accent === PURGE_KEY ? {
...currentColorCustomizationsConfig,
...getThemeColorCustomizationsConfig()
} : {
...currentColorCustomizationsConfig,
...getThemeColorCustomizationsConfig(themeConfig.accents[accent])
};
if (accent === PURGE_KEY) {
const {[currentThemeID]: _, ...rest} = currentColorCustomizationsConfig;
config = rest;
} else {
config = {
...currentColorCustomizationsConfig,
[`[${currentThemeID}]`]: {
...getThemeColorCustomizationsConfig(themeConfig.accents[accent])
}
};
}
await updateColorCustomizationsConfig(config);
await settingsManager.updateSetting('accent', accent);

View file

@ -8,6 +8,15 @@ type MaterialThemeConfig = {
changelog?: { lastversion?: string };
};
type PackageJSON = {
version: string;
contributes: {
themes: Array<{
label: string;
}>;
};
};
type InstallationType = {
firstInstall: boolean;
update: boolean;
@ -15,7 +24,7 @@ type InstallationType = {
export interface IExtensionManager {
init: () => Promise<void>;
getPackageJSON: () => Record<string, any>;
getPackageJSON: () => PackageJSON;
getConfig: () => MaterialThemeConfig;
getInstallationType: () => Record<string, unknown>;
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)});
}
getPackageJSON(): Record<string, any> {
getPackageJSON(): PackageJSON {
return extensions.getExtension(MATERIAL_THEME_EXT_ID).packageJSON;
}