diff --git a/extensions/commands/accents-setter/index.ts b/extensions/commands/accents-setter/index.ts index 0f65c32..8f716c2 100644 --- a/extensions/commands/accents-setter/index.ts +++ b/extensions/commands/accents-setter/index.ts @@ -35,37 +35,46 @@ const isValidColour = (colour: string | null | undefined): boolean => /** * Sets workbench options */ -const setWorkbenchOptions = (accentSelected: string | undefined, config: any): Thenable => +const setWorkbenchOptions = (config: any): Thenable => vscode.workspace.getConfiguration().update('workbench.colorCustomizations', config, true) - .then(() => updateAccent(accentSelected), - reason => vscode.window.showErrorMessage(reason)); + .then(() => true, reason => vscode.window.showErrorMessage(reason)); /** * VSCode command */ -export default async (): Promise => { +export default async (accent?: string): Promise => { const themeConfigCommon = getDefaultValues(); const purgeColourKey: string = 'Remove accents'; - const options: string[] = Object.keys(themeConfigCommon.accents).concat(purgeColourKey); + const shouldUpdateAccent = Boolean(!accent); + let accentToSelect = accent; - // shows the quick pick dropdown and wait response - const accentSelected = await vscode.window.showQuickPick(options); + // If called without accent shows the quick pick dropdown and wait response + if (!accentToSelect) { + const options: string[] = Object.keys(themeConfigCommon.accents).concat(purgeColourKey); + const accentSelected = await vscode.window.showQuickPick(options); - if (accentSelected === null || accentSelected === undefined) { - return Promise.resolve(null); + if (accentSelected === null || accentSelected === undefined) { + return Promise.resolve(null); + } + + accentToSelect = accentSelected; } const config: any = vscode.workspace.getConfiguration().get('workbench.colorCustomizations'); - switch (accentSelected) { + switch (accentToSelect) { case purgeColourKey: assignColorCustomizations(undefined, config); - await setWorkbenchOptions(undefined, config); - return Promise.resolve(true); + return setWorkbenchOptions(config) + .then(() => updateAccent(undefined)) + .then(() => Promise.resolve(true)); default: - assignColorCustomizations(themeConfigCommon.accents[accentSelected], config); - await setWorkbenchOptions(accentSelected, config); - return Promise.resolve(true); + assignColorCustomizations(themeConfigCommon.accents[accentToSelect], config); + return setWorkbenchOptions(config) + .then(() => + shouldUpdateAccent ? updateAccent(accentToSelect) : Promise.resolve(accentToSelect) + ) + .then(() => Promise.resolve(true)); } }; diff --git a/extensions/commands/theme-icons/index.ts b/extensions/commands/theme-icons/index.ts index 4c31aef..503f360 100644 --- a/extensions/commands/theme-icons/index.ts +++ b/extensions/commands/theme-icons/index.ts @@ -29,8 +29,6 @@ const replaceIconPathWithAccent = (iconPath: string, accentName: string): string return iconPath.replace('.svg', `.accent.${ accentName }.svg`); }; -let fixIconsRunning: boolean = false; - /** * Fix icons when flag auto-fix is active and current theme is Material */ @@ -41,10 +39,6 @@ export default async () => { deferred.reject = reject; }); - if (fixIconsRunning) { - return deferred.resolve(); - } - // Current theme id set on VSCode ("label" of the package.json) const themeLabel = getCurrentThemeID(); @@ -53,8 +47,6 @@ export default async () => { return deferred.resolve(); } - fixIconsRunning = true; - const DEFAULTS = getDefaultValues(); const CUSTOM_SETTINGS = getCustomSettings(); @@ -96,8 +88,6 @@ export default async () => { deferred.reject(err); return; } - - fixIconsRunning = false; deferred.resolve(); }); diff --git a/extensions/helpers/configuration-change.ts b/extensions/helpers/configuration-change.ts index 537e401..d323238 100644 --- a/extensions/helpers/configuration-change.ts +++ b/extensions/helpers/configuration-change.ts @@ -1,10 +1,10 @@ import { ConfigurationChangeEvent } from 'vscode'; -import {isMaterialThemeIcons, isMaterialTheme} from './settings'; +import {isMaterialThemeIcons, isMaterialTheme, getAccent} from './settings'; import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode'; - import handleAutoapply from './handle-autoapply'; +import {accentsSetter} from '../commands'; const onIconsChanged = () => { const currentIconsTheme = getCurrentThemeIconsID(); @@ -16,10 +16,24 @@ const onThemeChanged = () => { return handleAutoapply(isMaterialTheme(currentTheme)); }; +const onAccentChanged = () => { + const currentTheme = getCurrentThemeID(); + const currentIconsTheme = getCurrentThemeIconsID(); + const currentAccent = getAccent(); + return accentsSetter(currentAccent) + .then(() => + handleAutoapply( + isMaterialTheme(currentTheme) && isMaterialThemeIcons(currentIconsTheme) + ) + ); +}; + export const onChangeConfiguration = (event: ConfigurationChangeEvent) => { const isColorTheme = event.affectsConfiguration('workbench.colorTheme'); const isIconTheme = event.affectsConfiguration('workbench.iconTheme'); + const isAccent = event.affectsConfiguration('materialTheme.accent'); return isIconTheme ? onIconsChanged() : - isColorTheme ? onThemeChanged() : null; + isColorTheme ? onThemeChanged() : + isAccent ? onAccentChanged() : null; }; diff --git a/extensions/helpers/handle-autoapply.ts b/extensions/helpers/handle-autoapply.ts index 0aa0c50..c7188cc 100644 --- a/extensions/helpers/handle-autoapply.ts +++ b/extensions/helpers/handle-autoapply.ts @@ -2,13 +2,16 @@ import {isAutoApplyEnable, isReloadNotificationEnable} from './settings'; import {infoMessage} from './messages'; import {fixIcons} from '../commands'; +let fixIconsRunning: boolean = false; + export default async (doubleCheck: boolean) => { - if (!doubleCheck) { + if (!doubleCheck || fixIconsRunning) { return; } if (isAutoApplyEnable()) { - return fixIcons(); + fixIconsRunning = true; + return fixIcons().then(() => fixIconsRunning = false); } if (!isReloadNotificationEnable()) { @@ -18,6 +21,7 @@ export default async (doubleCheck: boolean) => { const result = await infoMessage(); if (result.reload) { - return fixIcons(); + fixIconsRunning = true; + return fixIcons().then(() => fixIconsRunning = false); } };