feat: added integration for VSC settings preview (#242)
This commit is contained in:
parent
e59b3e3eae
commit
e783b1c67d
4 changed files with 48 additions and 31 deletions
|
@ -35,37 +35,46 @@ const isValidColour = (colour: string | null | undefined): boolean =>
|
|||
/**
|
||||
* Sets workbench options
|
||||
*/
|
||||
const setWorkbenchOptions = (accentSelected: string | undefined, config: any): Thenable<string> =>
|
||||
const setWorkbenchOptions = (config: any): Thenable<boolean> =>
|
||||
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<boolean> => {
|
||||
export default async (accent?: string): Promise<boolean> => {
|
||||
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
|
||||
// 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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue