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
|
* 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)
|
vscode.workspace.getConfiguration().update('workbench.colorCustomizations', config, true)
|
||||||
.then(() => updateAccent(accentSelected),
|
.then(() => true, reason => vscode.window.showErrorMessage(reason));
|
||||||
reason => vscode.window.showErrorMessage(reason));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VSCode command
|
* VSCode command
|
||||||
*/
|
*/
|
||||||
export default async (): Promise<boolean> => {
|
export default async (accent?: string): Promise<boolean> => {
|
||||||
const themeConfigCommon = getDefaultValues();
|
const themeConfigCommon = getDefaultValues();
|
||||||
const purgeColourKey: string = 'Remove accents';
|
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);
|
const accentSelected = await vscode.window.showQuickPick(options);
|
||||||
|
|
||||||
if (accentSelected === null || accentSelected === undefined) {
|
if (accentSelected === null || accentSelected === undefined) {
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accentToSelect = accentSelected;
|
||||||
|
}
|
||||||
|
|
||||||
const config: any = vscode.workspace.getConfiguration().get('workbench.colorCustomizations');
|
const config: any = vscode.workspace.getConfiguration().get('workbench.colorCustomizations');
|
||||||
|
|
||||||
switch (accentSelected) {
|
switch (accentToSelect) {
|
||||||
case purgeColourKey:
|
case purgeColourKey:
|
||||||
assignColorCustomizations(undefined, config);
|
assignColorCustomizations(undefined, config);
|
||||||
await setWorkbenchOptions(undefined, config);
|
return setWorkbenchOptions(config)
|
||||||
return Promise.resolve(true);
|
.then(() => updateAccent(undefined))
|
||||||
|
.then(() => Promise.resolve(true));
|
||||||
default:
|
default:
|
||||||
assignColorCustomizations(themeConfigCommon.accents[accentSelected], config);
|
assignColorCustomizations(themeConfigCommon.accents[accentToSelect], config);
|
||||||
await setWorkbenchOptions(accentSelected, config);
|
return setWorkbenchOptions(config)
|
||||||
return Promise.resolve(true);
|
.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`);
|
return iconPath.replace('.svg', `.accent.${ accentName }.svg`);
|
||||||
};
|
};
|
||||||
|
|
||||||
let fixIconsRunning: boolean = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix icons when flag auto-fix is active and current theme is Material
|
* Fix icons when flag auto-fix is active and current theme is Material
|
||||||
*/
|
*/
|
||||||
|
@ -41,10 +39,6 @@ export default async () => {
|
||||||
deferred.reject = reject;
|
deferred.reject = reject;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (fixIconsRunning) {
|
|
||||||
return deferred.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Current theme id set on VSCode ("label" of the package.json)
|
// Current theme id set on VSCode ("label" of the package.json)
|
||||||
const themeLabel = getCurrentThemeID();
|
const themeLabel = getCurrentThemeID();
|
||||||
|
|
||||||
|
@ -53,8 +47,6 @@ export default async () => {
|
||||||
return deferred.resolve();
|
return deferred.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
fixIconsRunning = true;
|
|
||||||
|
|
||||||
const DEFAULTS = getDefaultValues();
|
const DEFAULTS = getDefaultValues();
|
||||||
const CUSTOM_SETTINGS = getCustomSettings();
|
const CUSTOM_SETTINGS = getCustomSettings();
|
||||||
|
|
||||||
|
@ -96,8 +88,6 @@ export default async () => {
|
||||||
deferred.reject(err);
|
deferred.reject(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixIconsRunning = false;
|
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import {
|
import {
|
||||||
ConfigurationChangeEvent
|
ConfigurationChangeEvent
|
||||||
} from 'vscode';
|
} from 'vscode';
|
||||||
import {isMaterialThemeIcons, isMaterialTheme} from './settings';
|
import {isMaterialThemeIcons, isMaterialTheme, getAccent} from './settings';
|
||||||
import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode';
|
import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode';
|
||||||
|
|
||||||
import handleAutoapply from './handle-autoapply';
|
import handleAutoapply from './handle-autoapply';
|
||||||
|
import {accentsSetter} from '../commands';
|
||||||
|
|
||||||
const onIconsChanged = () => {
|
const onIconsChanged = () => {
|
||||||
const currentIconsTheme = getCurrentThemeIconsID();
|
const currentIconsTheme = getCurrentThemeIconsID();
|
||||||
|
@ -16,10 +16,24 @@ const onThemeChanged = () => {
|
||||||
return handleAutoapply(isMaterialTheme(currentTheme));
|
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) => {
|
export const onChangeConfiguration = (event: ConfigurationChangeEvent) => {
|
||||||
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
|
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
|
||||||
const isIconTheme = event.affectsConfiguration('workbench.iconTheme');
|
const isIconTheme = event.affectsConfiguration('workbench.iconTheme');
|
||||||
|
const isAccent = event.affectsConfiguration('materialTheme.accent');
|
||||||
|
|
||||||
return isIconTheme ? onIconsChanged() :
|
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 {infoMessage} from './messages';
|
||||||
import {fixIcons} from '../commands';
|
import {fixIcons} from '../commands';
|
||||||
|
|
||||||
|
let fixIconsRunning: boolean = false;
|
||||||
|
|
||||||
export default async (doubleCheck: boolean) => {
|
export default async (doubleCheck: boolean) => {
|
||||||
if (!doubleCheck) {
|
if (!doubleCheck || fixIconsRunning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAutoApplyEnable()) {
|
if (isAutoApplyEnable()) {
|
||||||
return fixIcons();
|
fixIconsRunning = true;
|
||||||
|
return fixIcons().then(() => fixIconsRunning = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isReloadNotificationEnable()) {
|
if (!isReloadNotificationEnable()) {
|
||||||
|
@ -18,6 +21,7 @@ export default async (doubleCheck: boolean) => {
|
||||||
const result = await infoMessage();
|
const result = await infoMessage();
|
||||||
|
|
||||||
if (result.reload) {
|
if (result.reload) {
|
||||||
return fixIcons();
|
fixIconsRunning = true;
|
||||||
|
return fixIcons().then(() => fixIconsRunning = false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue