feat: wrap accent settings inside variant name (#504)
This commit is contained in:
parent
58d80a8df6
commit
596b6e68a9
2 changed files with 31 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue