2018-04-30 09:55:47 +02:00
|
|
|
import {
|
|
|
|
workspace as Workspace,
|
|
|
|
commands as Commands
|
|
|
|
} from 'vscode';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
import {THEME_ACCENTS_SETTER} from './commands/accents-setter/index';
|
|
|
|
import {THEME_ICONS} from './commands/theme-icons/index';
|
|
|
|
import {shouldShowChangelog, showChangelog} from './helpers/changelog';
|
|
|
|
import {reloadWindow, getCurrentThemeID, setIconsID} from './helpers/vscode';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-04-21 18:17:20 +02:00
|
|
|
const isMaterialTheme = (currentTheme: string): boolean =>
|
|
|
|
currentTheme.includes('Material Theme');
|
|
|
|
|
2018-04-30 09:55:47 +02:00
|
|
|
export function activate() {
|
|
|
|
const config = Workspace.getConfiguration();
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-04-30 09:55:47 +02:00
|
|
|
// Listen on set theme: when the theme is Material Theme, just adjust icon and accent.
|
|
|
|
Workspace.onDidChangeConfiguration(event => {
|
2018-04-21 18:17:20 +02:00
|
|
|
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
|
|
|
|
const currentTheme = getCurrentThemeID();
|
2018-05-03 11:39:51 +02:00
|
|
|
// tslint:disable-next-line:early-exit
|
2018-04-21 18:17:20 +02:00
|
|
|
if (isColorTheme && isMaterialTheme(currentTheme)) {
|
2018-04-30 09:55:47 +02:00
|
|
|
setIconsID('eq-material-theme-icons')
|
|
|
|
.then(() => THEME_ICONS().catch(error => console.trace(error)))
|
|
|
|
.then(() => reloadWindow());
|
2018-04-21 18:17:20 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-30 09:55:47 +02:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2018-04-30 09:55:47 +02:00
|
|
|
// 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
|
|
|
}
|