2018-04-20 20:07:36 +02:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
|
|
|
import { IGenericObject } from "./interfaces/igeneric-object";
|
|
|
|
import { THEME_ACCENTS_SETTER } from "./commands/accents-setter/index";
|
2018-04-20 22:18:31 +02:00
|
|
|
import { THEME_ICONS } from "./commands/theme-icons/index";
|
2018-04-20 20:07:36 +02:00
|
|
|
import { shouldShowChangelog, showChangelog } from './helpers/changelog';
|
2018-04-21 18:17:20 +02:00
|
|
|
import { reloadWindow, getCurrentThemeID, setIconsID } from "./helpers/vscode";
|
2018-04-20 20:07:36 +02:00
|
|
|
|
|
|
|
enum Commands {
|
|
|
|
ACCENTS,
|
|
|
|
CHANGELOG,
|
2018-04-20 22:18:31 +02:00
|
|
|
THEME_ICONS
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const OPTIONS: IGenericObject<number> = {
|
|
|
|
'🖍 Change accent color': Commands.ACCENTS,
|
2018-04-20 22:18:31 +02:00
|
|
|
'🎨 Adapt icons': Commands.THEME_ICONS,
|
2018-04-20 20:07:36 +02:00
|
|
|
'🚧 Show changelog': Commands.CHANGELOG
|
|
|
|
}
|
|
|
|
|
2018-04-21 18:17:20 +02:00
|
|
|
const isMaterialTheme = (currentTheme: string): boolean =>
|
|
|
|
currentTheme.includes('Material Theme');
|
|
|
|
|
2018-04-20 20:07:36 +02:00
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
|
|
if (vscode.workspace.getConfiguration().has('materialTheme.cache.workbench.accent')) {
|
|
|
|
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.accent', undefined, true);
|
|
|
|
}
|
|
|
|
|
2018-04-21 18:17:20 +02:00
|
|
|
vscode.workspace.onDidChangeConfiguration(async event => {
|
|
|
|
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
|
|
|
|
const currentTheme = getCurrentThemeID();
|
|
|
|
if (isColorTheme && isMaterialTheme(currentTheme)) {
|
|
|
|
await setIconsID('eq-material-theme-icons');
|
|
|
|
await THEME_ICONS().catch(error => console.trace(error));
|
|
|
|
reloadWindow();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-20 20:07:36 +02:00
|
|
|
if (shouldShowChangelog()) {
|
|
|
|
showChangelog();
|
|
|
|
}
|
|
|
|
|
|
|
|
// registering the command
|
|
|
|
let command = vscode.commands.registerCommand('material.theme.config', () => {
|
|
|
|
// the user is going to choose what aspect of theme to config
|
|
|
|
vscode.window.showQuickPick(Object.keys(OPTIONS)).then(response => {
|
|
|
|
// switching selected option
|
|
|
|
switch(OPTIONS[response]) {
|
|
|
|
case Commands.ACCENTS:
|
|
|
|
THEME_ACCENTS_SETTER();
|
|
|
|
break;
|
|
|
|
case Commands.CHANGELOG:
|
|
|
|
showChangelog();
|
|
|
|
break;
|
2018-04-20 22:18:31 +02:00
|
|
|
case Commands.THEME_ICONS:
|
|
|
|
THEME_ICONS().then(() => reloadWindow()).catch(error => console.trace(error));
|
2018-04-20 20:07:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
context.subscriptions.push(command);
|
|
|
|
}
|