diff --git a/extensions/helpers/configuration-change.ts b/extensions/helpers/configuration-change.ts index ef1e1aa..2ce4074 100644 --- a/extensions/helpers/configuration-change.ts +++ b/extensions/helpers/configuration-change.ts @@ -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; }; diff --git a/extensions/helpers/handle-autoapply.ts b/extensions/helpers/handle-autoapply.ts new file mode 100644 index 0000000..b2d914b --- /dev/null +++ b/extensions/helpers/handle-autoapply.ts @@ -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(); + } +}; diff --git a/extensions/helpers/messages.ts b/extensions/helpers/messages.ts index a9bfc54..470ec59 100644 --- a/extensions/helpers/messages.ts +++ b/extensions/helpers/messages.ts @@ -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; diff --git a/extensions/helpers/settings.ts b/extensions/helpers/settings.ts index 1c2073b..c726015 100644 --- a/extensions/helpers/settings.ts +++ b/extensions/helpers/settings.ts @@ -22,7 +22,14 @@ export function getCustomSettings(): IThemeCustomProperties { * Get autoApplyIcons */ export function isAutoApplyEnable(): boolean { - return vscode.workspace.getConfiguration().get('materialTheme.autoApplyIcons', true); + return vscode.workspace.getConfiguration().get('materialTheme.autoApplyIcons'); +} + +/** + * Get showReloadNotification + */ +export function isReloadNotificationEnable(): boolean { + return vscode.workspace.getConfiguration().get('materialTheme.showReloadNotification'); } /** diff --git a/extensions/material.theme.config.ts b/extensions/material.theme.config.ts index f13f22d..900b75f 100644 --- a/extensions/material.theme.config.ts +++ b/extensions/material.theme.config.ts @@ -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());