feat(Reload notification): added support never show again notification
This commit is contained in:
parent
a42b3a0f86
commit
440c1049cf
5 changed files with 70 additions and 33 deletions
|
@ -1,13 +1,10 @@
|
|||
import {
|
||||
ConfigurationChangeEvent
|
||||
} from 'vscode';
|
||||
import {getCustomSettings, isMaterialThemeIcons, isAutoApplyEnable, isMaterialTheme} from './settings';
|
||||
import {getCustomSettings, isMaterialThemeIcons, isMaterialTheme} from './settings';
|
||||
import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode';
|
||||
|
||||
import * as ThemeCommands from './../commands';
|
||||
import {infoMessage} from './messages';
|
||||
|
||||
const icons = () => isAutoApplyEnable() ? ThemeCommands.fixIcons() : infoMessage();
|
||||
import handleAutoapply from './handle-autoapply';
|
||||
|
||||
const onIconsChanged = () => {
|
||||
const customSettings = getCustomSettings();
|
||||
|
@ -16,27 +13,18 @@ const onIconsChanged = () => {
|
|||
}
|
||||
|
||||
const currentIconsTheme = getCurrentThemeIconsID();
|
||||
if (isMaterialThemeIcons(currentIconsTheme)) {
|
||||
return icons();
|
||||
}
|
||||
return handleAutoapply(isMaterialThemeIcons(currentIconsTheme));
|
||||
};
|
||||
|
||||
const onThemeChanged = () => {
|
||||
const currentTheme = getCurrentThemeID();
|
||||
if (isMaterialTheme(currentTheme)) {
|
||||
return icons();
|
||||
}
|
||||
return handleAutoapply(isMaterialTheme(currentTheme));
|
||||
};
|
||||
|
||||
export const onChangeConfiguration = (event: ConfigurationChangeEvent) => {
|
||||
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
|
||||
const isIconTheme = event.affectsConfiguration('workbench.iconTheme');
|
||||
|
||||
if (isIconTheme) {
|
||||
return onIconsChanged();
|
||||
}
|
||||
|
||||
if (isColorTheme) {
|
||||
return onThemeChanged();
|
||||
}
|
||||
return isIconTheme ? onIconsChanged() :
|
||||
isColorTheme ? onThemeChanged() : null;
|
||||
};
|
||||
|
|
31
extensions/helpers/handle-autoapply.ts
Normal file
31
extensions/helpers/handle-autoapply.ts
Normal 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();
|
||||
}
|
||||
};
|
|
@ -2,12 +2,10 @@ import {
|
|||
window as Window
|
||||
} from 'vscode';
|
||||
|
||||
import * as ThemeCommands from './../commands';
|
||||
|
||||
const MESSAGES = {
|
||||
INFO: {
|
||||
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: {
|
||||
message: 'Material Theme was updated. Check the release notes for more details.',
|
||||
|
@ -20,22 +18,36 @@ const MESSAGES = {
|
|||
};
|
||||
|
||||
export const infoMessage = async () => {
|
||||
if (await Window.showInformationMessage(
|
||||
const result = await Window.showInformationMessage(
|
||||
MESSAGES.INFO.message,
|
||||
...MESSAGES.INFO.options as any
|
||||
) === MESSAGES.INFO.options.ok) {
|
||||
ThemeCommands.fixIcons();
|
||||
MESSAGES.INFO.options.ok,
|
||||
MESSAGES.INFO.options.autoreload,
|
||||
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 () =>
|
||||
await Window.showInformationMessage(
|
||||
MESSAGES.CHANGELOG.message,
|
||||
...MESSAGES.CHANGELOG.options as any
|
||||
MESSAGES.CHANGELOG.options.ok,
|
||||
MESSAGES.CHANGELOG.options.cancel
|
||||
) === MESSAGES.CHANGELOG.options.ok;
|
||||
|
||||
export const installationMessage = async () =>
|
||||
await Window.showInformationMessage(
|
||||
MESSAGES.INSTALLATION.message,
|
||||
...MESSAGES.INSTALLATION.options as any
|
||||
MESSAGES.INSTALLATION.options.ok,
|
||||
MESSAGES.INSTALLATION.options.cancel,
|
||||
) === MESSAGES.INSTALLATION.options.ok;
|
||||
|
|
|
@ -22,7 +22,14 @@ export function getCustomSettings(): IThemeCustomProperties {
|
|||
* Get autoApplyIcons
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,11 +4,12 @@ import {
|
|||
} from 'vscode';
|
||||
|
||||
import * as ThemeCommands from './commands';
|
||||
import {isAutoApplyEnable, setCustomSetting} from './helpers/settings';
|
||||
import {setCustomSetting} from './helpers/settings';
|
||||
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 writeChangelog from './helpers/write-changelog';
|
||||
import handleAutoapply from './helpers/handle-autoapply';
|
||||
|
||||
export async function activate() {
|
||||
const config = Workspace.getConfiguration();
|
||||
|
@ -39,9 +40,7 @@ export async function activate() {
|
|||
// Registering commands
|
||||
Commands.registerCommand('materialTheme.setAccent', async () => {
|
||||
const wasSet = await ThemeCommands.accentsSetter();
|
||||
if (wasSet) {
|
||||
return isAutoApplyEnable() ? ThemeCommands.fixIcons() : infoMessage();
|
||||
}
|
||||
handleAutoapply(wasSet);
|
||||
});
|
||||
Commands.registerCommand('materialTheme.fixIcons', () => ThemeCommands.fixIcons());
|
||||
Commands.registerCommand('materialTheme.toggleApplyIcons', () => ThemeCommands.toggleApplyIcons());
|
||||
|
|
Loading…
Reference in a new issue