vsc-material-theme/extensions/material.theme.config.ts

46 lines
1.6 KiB
TypeScript
Raw Normal View History

import {
workspace as Workspace,
commands as Commands
} from 'vscode';
2018-04-20 20:07:36 +02:00
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';
import { reloadWindow, getCurrentThemeID, setIconsID } from "./helpers/vscode";
2018-04-20 20:07:36 +02:00
const isMaterialTheme = (currentTheme: string): boolean =>
currentTheme.includes('Material Theme');
export function activate() {
const config = Workspace.getConfiguration();
2018-04-20 20:07:36 +02:00
// Listen on set theme: when the theme is Material Theme, just adjust icon and accent.
Workspace.onDidChangeConfiguration(event => {
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
const currentTheme = getCurrentThemeID();
if (isColorTheme && isMaterialTheme(currentTheme)) {
setIconsID('eq-material-theme-icons')
.then(() => THEME_ICONS().catch(error => console.trace(error)))
.then(() => reloadWindow());
}
});
// Delete old configuration, must remove with next major release
if (config.has('materialTheme.cache.workbench')) {
config.update('materialTheme.cache.workbench', undefined, true);
}
2018-04-20 20:07:36 +02:00
if (shouldShowChangelog()) {
showChangelog();
}
// Registering commands
Commands.registerCommand('materialTheme.setAccent', () => THEME_ACCENTS_SETTER());
Commands.registerCommand('materialTheme.fixIcons', () =>
THEME_ICONS()
.then(() => reloadWindow())
.catch(err => console.trace(err))
);
Commands.registerCommand('materialTheme.showChangelog', () => showChangelog());
2018-04-20 20:07:36 +02:00
}