feat(Reload notification): added support never show again notification

This commit is contained in:
LasaleFamine 2018-08-12 12:48:23 +02:00
parent a42b3a0f86
commit 440c1049cf
5 changed files with 70 additions and 33 deletions

View file

@ -1,13 +1,10 @@
import { import {
ConfigurationChangeEvent ConfigurationChangeEvent
} from 'vscode'; } from 'vscode';
import {getCustomSettings, isMaterialThemeIcons, isAutoApplyEnable, isMaterialTheme} from './settings'; import {getCustomSettings, isMaterialThemeIcons, isMaterialTheme} from './settings';
import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode'; import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode';
import * as ThemeCommands from './../commands'; import handleAutoapply from './handle-autoapply';
import {infoMessage} from './messages';
const icons = () => isAutoApplyEnable() ? ThemeCommands.fixIcons() : infoMessage();
const onIconsChanged = () => { const onIconsChanged = () => {
const customSettings = getCustomSettings(); const customSettings = getCustomSettings();
@ -16,27 +13,18 @@ const onIconsChanged = () => {
} }
const currentIconsTheme = getCurrentThemeIconsID(); const currentIconsTheme = getCurrentThemeIconsID();
if (isMaterialThemeIcons(currentIconsTheme)) { return handleAutoapply(isMaterialThemeIcons(currentIconsTheme));
return icons();
}
}; };
const onThemeChanged = () => { const onThemeChanged = () => {
const currentTheme = getCurrentThemeID(); const currentTheme = getCurrentThemeID();
if (isMaterialTheme(currentTheme)) { return handleAutoapply(isMaterialTheme(currentTheme));
return icons();
}
}; };
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');
if (isIconTheme) { return isIconTheme ? onIconsChanged() :
return onIconsChanged(); isColorTheme ? onThemeChanged() : null;
}
if (isColorTheme) {
return onThemeChanged();
}
}; };

View file

@ -0,0 +1,31 @@
import {isAutoApplyEnable, isReloadNotificationEnable, setCustomSetting} from './settings';
import {infoMessage} from './messages';
import {fixIcons} from '../commands';
export default async (doubleCheck: boolean) => {
if (!doubleCheck) {
return;
}
if (isAutoApplyEnable()) {
return fixIcons();
}
if (!isReloadNotificationEnable()) {
return;
}
const result = await infoMessage();
if (result.nomore) {
return setCustomSetting('showReloadNotification', false);
}
if (result.autoreload) {
setCustomSetting('autoApplyIcons', true);
}
if (result.reload) {
return fixIcons();
}
};

View file

@ -2,12 +2,10 @@ import {
window as Window window as Window
} from 'vscode'; } from 'vscode';
import * as ThemeCommands from './../commands';
const MESSAGES = { const MESSAGES = {
INFO: { INFO: {
message: 'Do you want to reload to apply Material Theme Icons to enjoy the full experience?', message: 'Do you want to reload to apply Material Theme Icons to enjoy the full experience?',
options: {ok: 'Yeah, releoad', cancel: 'No, thank you'} options: {ok: 'Yeah, reload', autoreload: 'Yes and enable auto-reload', cancel: 'No, thank you', nomore: 'Never show again'}
}, },
CHANGELOG: { CHANGELOG: {
message: 'Material Theme was updated. Check the release notes for more details.', message: 'Material Theme was updated. Check the release notes for more details.',
@ -20,22 +18,36 @@ const MESSAGES = {
}; };
export const infoMessage = async () => { export const infoMessage = async () => {
if (await Window.showInformationMessage( const result = await Window.showInformationMessage(
MESSAGES.INFO.message, MESSAGES.INFO.message,
...MESSAGES.INFO.options as any MESSAGES.INFO.options.ok,
) === MESSAGES.INFO.options.ok) { MESSAGES.INFO.options.autoreload,
ThemeCommands.fixIcons(); MESSAGES.INFO.options.cancel,
MESSAGES.INFO.options.nomore
);
switch (result) {
case MESSAGES.INFO.options.ok:
return {reload: true};
case MESSAGES.INFO.options.autoreload:
return {reload: true, autoreload: true};
case MESSAGES.INFO.options.nomore:
return {nomore: true};
default:
return {};
} }
}; };
export const changelogMessage = async () => export const changelogMessage = async () =>
await Window.showInformationMessage( await Window.showInformationMessage(
MESSAGES.CHANGELOG.message, MESSAGES.CHANGELOG.message,
...MESSAGES.CHANGELOG.options as any MESSAGES.CHANGELOG.options.ok,
MESSAGES.CHANGELOG.options.cancel
) === MESSAGES.CHANGELOG.options.ok; ) === MESSAGES.CHANGELOG.options.ok;
export const installationMessage = async () => export const installationMessage = async () =>
await Window.showInformationMessage( await Window.showInformationMessage(
MESSAGES.INSTALLATION.message, MESSAGES.INSTALLATION.message,
...MESSAGES.INSTALLATION.options as any MESSAGES.INSTALLATION.options.ok,
MESSAGES.INSTALLATION.options.cancel,
) === MESSAGES.INSTALLATION.options.ok; ) === MESSAGES.INSTALLATION.options.ok;

View file

@ -22,7 +22,14 @@ export function getCustomSettings(): IThemeCustomProperties {
* Get autoApplyIcons * Get autoApplyIcons
*/ */
export function isAutoApplyEnable(): boolean { export function isAutoApplyEnable(): boolean {
return vscode.workspace.getConfiguration().get<boolean>('materialTheme.autoApplyIcons', true); return vscode.workspace.getConfiguration().get<boolean>('materialTheme.autoApplyIcons');
}
/**
* Get showReloadNotification
*/
export function isReloadNotificationEnable(): boolean {
return vscode.workspace.getConfiguration().get<boolean>('materialTheme.showReloadNotification');
} }
/** /**

View file

@ -4,11 +4,12 @@ import {
} from 'vscode'; } from 'vscode';
import * as ThemeCommands from './commands'; import * as ThemeCommands from './commands';
import {isAutoApplyEnable, setCustomSetting} from './helpers/settings'; import {setCustomSetting} from './helpers/settings';
import {onChangeConfiguration} from './helpers/configuration-change'; import {onChangeConfiguration} from './helpers/configuration-change';
import {infoMessage, changelogMessage, installationMessage} from './helpers/messages'; import {changelogMessage, installationMessage} from './helpers/messages';
import checkInstallation from './helpers/check-installation'; import checkInstallation from './helpers/check-installation';
import writeChangelog from './helpers/write-changelog'; import writeChangelog from './helpers/write-changelog';
import handleAutoapply from './helpers/handle-autoapply';
export async function activate() { export async function activate() {
const config = Workspace.getConfiguration(); const config = Workspace.getConfiguration();
@ -39,9 +40,7 @@ export async function activate() {
// Registering commands // Registering commands
Commands.registerCommand('materialTheme.setAccent', async () => { Commands.registerCommand('materialTheme.setAccent', async () => {
const wasSet = await ThemeCommands.accentsSetter(); const wasSet = await ThemeCommands.accentsSetter();
if (wasSet) { handleAutoapply(wasSet);
return isAutoApplyEnable() ? ThemeCommands.fixIcons() : infoMessage();
}
}); });
Commands.registerCommand('materialTheme.fixIcons', () => ThemeCommands.fixIcons()); Commands.registerCommand('materialTheme.fixIcons', () => ThemeCommands.fixIcons());
Commands.registerCommand('materialTheme.toggleApplyIcons', () => ThemeCommands.toggleApplyIcons()); Commands.registerCommand('materialTheme.toggleApplyIcons', () => ThemeCommands.toggleApplyIcons());