Merge branch 'develop'

This commit is contained in:
Mattia Astorino 2018-08-18 10:12:48 +02:00
commit fd149c168b
25 changed files with 202 additions and 110 deletions

View file

@ -4,4 +4,5 @@ about: Give us your feedback about this extension
--- ---
<!-- Love vsc-material-theme? Please consider supporting our collective:
👉 https://opencollective.com/vsc-material-theme/donate -->

View file

@ -11,8 +11,7 @@ import {
import { import {
isAccent, isAccent,
getCustomSettings, getCustomSettings,
isMaterialTheme, isMaterialTheme
setCustomSetting
} from './../../helpers/settings'; } from './../../helpers/settings';
import {getCurrentThemeID, setIconsID, getCurrentThemeIconsID, reloadWindow} from './../../helpers/vscode'; import {getCurrentThemeID, setIconsID, getCurrentThemeIconsID, reloadWindow} from './../../helpers/vscode';
import {CHARSET} from './../../consts/files'; import {CHARSET} from './../../consts/files';
@ -30,6 +29,8 @@ const replaceIconPathWithAccent = (iconPath: string, accentName: string): string
return iconPath.replace('.svg', `.accent.${ accentName }.svg`); return iconPath.replace('.svg', `.accent.${ accentName }.svg`);
}; };
let fixIconsRunning: boolean = false;
/** /**
* Fix icons when flag auto-fix is active and current theme is Material * Fix icons when flag auto-fix is active and current theme is Material
*/ */
@ -40,6 +41,10 @@ export default async () => {
deferred.reject = reject; deferred.reject = reject;
}); });
if (fixIconsRunning) {
return deferred.resolve();
}
// Current theme id set on VSCode ("label" of the package.json) // Current theme id set on VSCode ("label" of the package.json)
const themeLabel = getCurrentThemeID(); const themeLabel = getCurrentThemeID();
@ -48,7 +53,7 @@ export default async () => {
return deferred.resolve(); return deferred.resolve();
} }
await setCustomSetting('fixIconsRunning', true); fixIconsRunning = true;
const DEFAULTS = getDefaultValues(); const DEFAULTS = getDefaultValues();
const CUSTOM_SETTINGS = getCustomSettings(); const CUSTOM_SETTINGS = getCustomSettings();
@ -92,7 +97,7 @@ export default async () => {
return; return;
} }
await setCustomSetting('fixIconsRunning', false); fixIconsRunning = false;
deferred.resolve(); deferred.resolve();
}); });

View file

@ -108,6 +108,10 @@
"menubar.selectionForeground": { "menubar.selectionForeground": {
"alpha": 100, "alpha": 100,
"value": null "value": null
},
"settings.headerForeground": {
"alpha": 100,
"value": null
} }
}, },
"changelog": { "changelog": {

View file

@ -0,0 +1,34 @@
import {getDefaultValues, getPackageJSON} from './fs';
import {IInstallationType} from '../interfaces/iinstallation-type';
const splitVersion = (input: string): {major: number; minor: number; patch: number} => {
const [major, minor, patch] = input.split('.').map(i => parseInt(i, 10));
return {major, minor, patch};
};
export default (): IInstallationType => {
const out: IInstallationType = {
isUpdate: false,
isFirstInstall: false
};
const defaults = getDefaultValues();
const packageJSON = getPackageJSON();
const isFirstInstall = defaults.changelog === undefined ||
(defaults.changelog !== undefined && typeof defaults.changelog.lastversion !== 'string');
if (isFirstInstall) {
return {...out, isFirstInstall};
}
const versionCurrent = splitVersion(packageJSON.version);
const versionOld = isFirstInstall ? null : splitVersion(defaults.changelog.lastversion);
const isUpdate = !versionOld ||
versionCurrent.major > versionOld.major ||
versionCurrent.minor > versionOld.minor ||
versionCurrent.patch > versionOld.patch;
return {...out, isUpdate};
};

View file

@ -1,42 +1,25 @@
import { import {
ConfigurationChangeEvent ConfigurationChangeEvent
} from 'vscode'; } from 'vscode';
import {getCustomSettings, isMaterialThemeIcons, isAutoApplyEnable, isMaterialTheme} from './settings'; import {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();
if (customSettings.fixIconsRunning) {
return;
}
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,23 @@
import {isAutoApplyEnable, isReloadNotificationEnable} 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.reload) {
return fixIcons();
}
};

View file

@ -2,24 +2,46 @@ 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', cancel: 'No, thank you'}
}, },
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.',
options: {ok: 'Show me', cancel: 'Maybe later'} options: {ok: 'Show me', cancel: 'Maybe later'}
},
INSTALLATION: {
message: 'Thank you for installing Material Theme! Would you like to enable the auto-application (with window reload when needed) of the Material Theme icons?',
options: {ok: 'Sure!', cancel: 'Nope :('}
} }
}; };
export const infoMessage = async () => { export const infoMessage = async () => {
if (await Window.showInformationMessage(MESSAGES.INFO.message, MESSAGES.INFO.options.ok, MESSAGES.INFO.options.cancel) === MESSAGES.INFO.options.ok) { const result = await Window.showInformationMessage(
ThemeCommands.fixIcons(); MESSAGES.INFO.message,
MESSAGES.INFO.options.ok,
MESSAGES.INFO.options.cancel
);
switch (result) {
case MESSAGES.INFO.options.ok:
return {reload: true};
default:
return {};
} }
}; };
export const changelogMessage = async () => export const changelogMessage = async () =>
await Window.showInformationMessage(MESSAGES.CHANGELOG.message, MESSAGES.CHANGELOG.options.ok, MESSAGES.CHANGELOG.options.cancel) === MESSAGES.CHANGELOG.options.ok; await Window.showInformationMessage(
MESSAGES.CHANGELOG.message,
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.ok,
MESSAGES.INSTALLATION.options.cancel,
) === 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');
} }
/** /**
@ -59,7 +66,5 @@ export function setCustomSetting(settingName: string, value: any): Thenable<stri
* Updates accent name * Updates accent name
*/ */
export function updateAccent(accentName: string): Thenable<string> { export function updateAccent(accentName: string): Thenable<string> {
const prevAccent = getAccent(); return setCustomSetting('accent', accentName);
return setCustomSetting('accentPrevious', prevAccent)
.then(() => setCustomSetting('accent', accentName));
} }

View file

@ -1,35 +0,0 @@
import * as path from 'path';
import {IDefaults} from './../interfaces/idefaults';
import {getDefaultValues, getPackageJSON, writeFile} from './fs';
const splitVersion = (input: string): {major: number; minor: number; patch: number} => {
const [major, minor, patch] = input.split('.').map(i => parseInt(i, 10));
return {major, minor, patch};
};
const writeDefaults = (defaults: IDefaults) =>
writeFile(path.join('./extensions/defaults.json'), JSON.stringify(defaults, null, 2));
export default (): boolean => {
const defaults = getDefaultValues();
const packageJSON = getPackageJSON();
const defaultsNotPresent = defaults.changelog === undefined ||
(defaults.changelog !== undefined && typeof defaults.changelog.lastversion !== 'string');
const versionCurrent = splitVersion(packageJSON.version);
const versionOld = defaultsNotPresent ? null : splitVersion(defaults.changelog.lastversion);
const out = !versionOld ||
versionCurrent.major > versionOld.major ||
versionCurrent.minor > versionOld.minor ||
versionCurrent.patch > versionOld.patch;
const newChangelog = {...defaults.changelog, lastversion: packageJSON.version};
const newDefaults = {...defaults, changelog: newChangelog};
writeDefaults(newDefaults);
return out;
};

View file

@ -0,0 +1,16 @@
import * as path from 'path';
import {getDefaultValues, getPackageJSON, writeFile} from './fs';
import {IDefaults} from './../interfaces/idefaults';
const writeDefaults = (defaults: IDefaults) =>
writeFile(path.join('./extensions/defaults.json'), JSON.stringify(defaults, null, 2));
export default (): void => {
const defaults = getDefaultValues();
const packageJSON = getPackageJSON();
const newChangelog = {...defaults.changelog, lastversion: packageJSON.version};
const newDefaults = {...defaults, changelog: newChangelog};
writeDefaults(newDefaults);
};

View file

@ -0,0 +1,4 @@
export interface IInstallationType {
isUpdate: boolean;
isFirstInstall: boolean;
}

View file

@ -1,6 +1,4 @@
export interface IThemeCustomProperties { export interface IThemeCustomProperties {
accent?: string; accent?: string;
accentPrevious?: string;
autoApplyIcons?: boolean; autoApplyIcons?: boolean;
fixIconsRunning?: boolean;
} }

View file

@ -4,13 +4,18 @@ import {
} from 'vscode'; } from 'vscode';
import * as ThemeCommands from './commands'; import * as ThemeCommands from './commands';
import {isAutoApplyEnable} from './helpers/settings'; import {setCustomSetting} from './helpers/settings';
import {onChangeConfiguration} from './helpers/configuration-change'; import {onChangeConfiguration} from './helpers/configuration-change';
import {infoMessage, changelogMessage} from './helpers/messages'; import {changelogMessage, installationMessage} from './helpers/messages';
import shouldShowChangelog from './helpers/should-show-changelog'; import checkInstallation from './helpers/check-installation';
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();
const installationType = checkInstallation();
writeChangelog();
// Listen on set theme: when the theme is Material Theme, just adjust icon and accent. // Listen on set theme: when the theme is Material Theme, just adjust icon and accent.
Workspace.onDidChangeConfiguration(onChangeConfiguration); Workspace.onDidChangeConfiguration(onChangeConfiguration);
@ -20,20 +25,22 @@ export async function activate() {
config.update('materialTheme.cache.workbench', undefined, true); config.update('materialTheme.cache.workbench', undefined, true);
} }
if (shouldShowChangelog()) { if (installationType.isFirstInstall) {
const show = await changelogMessage(); const enableAutoApply = await installationMessage();
if (show) { await setCustomSetting('autoApplyIcons', enableAutoApply);
ThemeCommands.showChangelog(); // Set true always on new installation
} await setCustomSetting('showReloadNotification', true);
}
const shouldShowChangelog = (installationType.isFirstInstall || installationType.isUpdate) && await changelogMessage();
if (shouldShowChangelog) {
ThemeCommands.showChangelog();
} }
// Registering commands // Registering commands
Commands.registerCommand('materialTheme.setAccent', async () => { Commands.registerCommand('materialTheme.setAccent', async () => {
const wasSet = await ThemeCommands.accentsSetter(); const wasSet = await ThemeCommands.accentsSetter();
handleAutoapply(wasSet);
if (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());

View file

@ -85,21 +85,39 @@
"properties": { "properties": {
"materialTheme.accent": { "materialTheme.accent": {
"type": "string", "type": "string",
"description": "Current accent color selected" "default": "Blue",
}, "enum": [
"materialTheme.accentPrevious": { "Acid Lime",
"type": "string", "Blue",
"description": "Previous accent color selected" "Breaking Bad",
"Bright Teal",
"Cyan",
"Graphite",
"Indigo",
"Lime",
"Orange",
"Pink",
"Purple",
"Red",
"Sky",
"Tomato",
"Teal",
"Yellow"
],
"description": "Current accent color selected",
"scope": "window"
}, },
"materialTheme.autoApplyIcons": { "materialTheme.autoApplyIcons": {
"type": "boolean", "type": "boolean",
"description": "Enable/disable auto-apply of Material Theme icons", "description": "Enable/disable auto-apply of Material Theme icons with window reload when needed",
"default": true "default": false,
"scope": "window"
}, },
"materialTheme.fixIconsRunning": { "materialTheme.showReloadNotification": {
"type": "boolean", "type": "boolean",
"description": "For checking if the command is currently acting", "description": "Useful when autoApplyIcons is false and you want to be asked to reload the window when needed",
"default": false "default": true,
"scope": "window"
} }
} }
}, },

View file

@ -19,7 +19,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#61616150", "selection": "#61616150",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#2B2B2B",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbarsHover": "#00000030", "scrollbarsHover": "#00000030",

View file

@ -17,7 +17,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#61616150", "selection": "#61616150",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#2B2B2B",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbars": "#00000050", "scrollbars": "#00000050",

View file

@ -19,7 +19,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#80CBC420", "selection": "#80CBC420",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#303C41",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbarsHover": "#00000030", "scrollbarsHover": "#00000030",

View file

@ -17,7 +17,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#80CBC420", "selection": "#80CBC420",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#303C41",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbars": "#00000050", "scrollbars": "#00000050",

View file

@ -19,7 +19,7 @@
"lineHighlight": "#CCD7DA", "lineHighlight": "#CCD7DA",
"selection": "#80CBC440", "selection": "#80CBC440",
"shadow": "#00000020", "shadow": "#00000020",
"inputBackground": "#00000005", "inputBackground": "#EEEEEE",
"inputForeground": "#90A4AE", "inputForeground": "#90A4AE",
"inputBorder": "#00000010", "inputBorder": "#00000010",
"scrollbarsHover": "#00000030", "scrollbarsHover": "#00000030",

View file

@ -17,7 +17,7 @@
"lineHighlight": "#CCD7DA", "lineHighlight": "#CCD7DA",
"selection": "#80CBC440", "selection": "#80CBC440",
"shadow": "#00000020", "shadow": "#00000020",
"inputBackground": "#00000005", "inputBackground": "#EEEEEE",
"inputForeground": "#90A4AE", "inputForeground": "#90A4AE",
"inputBorder": "#00000010", "inputBorder": "#00000010",
"scrollbars": "#00000050", "scrollbars": "#00000050",

View file

@ -17,7 +17,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#717CB450", "selection": "#717CB450",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#1A1C25",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbars": "#00000050", "scrollbars": "#00000050",

View file

@ -17,7 +17,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#717CB450", "selection": "#717CB450",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#1A1C25",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbars": "#00000050", "scrollbars": "#00000050",

View file

@ -19,7 +19,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#717CB450", "selection": "#717CB450",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#333747",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbarsHover": "#00000030", "scrollbarsHover": "#00000030",

View file

@ -17,7 +17,7 @@
"lineHighlight": "#000000", "lineHighlight": "#000000",
"selection": "#717CB450", "selection": "#717CB450",
"shadow": "#00000030", "shadow": "#00000030",
"inputBackground": "#FFFFFF05", "inputBackground": "#333747",
"inputForeground": "#EEFFFF", "inputForeground": "#EEFFFF",
"inputBorder": "#FFFFFF10", "inputBorder": "#FFFFFF10",
"scrollbars": "#00000050", "scrollbars": "#00000050",

View file

@ -829,12 +829,19 @@
"breadcrumb.activeSelectionForeground": "{{commons.accents.Teal}}", "breadcrumb.activeSelectionForeground": "{{commons.accents.Teal}}",
"breadcrumbPicker.background": "{{variant.scheme.backgroundAlt}}", "breadcrumbPicker.background": "{{variant.scheme.backgroundAlt}}",
"menu.background": "{{variant.scheme.background}}", "menu.background": "{{variant.scheme.background}}",
"menu.foreground": "{{variant.scheme.sidebarForeground}}", "menu.foreground": "{{variant.scheme.foreground}}",
"menu.selectionBackground": "{{variant.scheme.inactiveSelectionBackground}}", "menu.selectionBackground": "{{variant.scheme.inactiveSelectionBackground}}",
"menu.selectionForeground": "{{commons.accents.Teal}}", "menu.selectionForeground": "{{commons.accents.Teal}}",
"menu.selectionBorder": "{{variant.scheme.inactiveSelectionBackground}}", "menu.selectionBorder": "{{variant.scheme.inactiveSelectionBackground}}",
"menubar.selectionBackground": "{{variant.scheme.inactiveSelectionBackground}}", "menubar.selectionBackground": "{{variant.scheme.inactiveSelectionBackground}}",
"menubar.selectionForeground": "{{commons.accents.Teal}}", "menubar.selectionForeground": "{{commons.accents.Teal}}",
"menubar.selectionBorder": "{{variant.scheme.inactiveSelectionBackground}}" "menubar.selectionBorder": "{{variant.scheme.inactiveSelectionBackground}}",
"settings.dropdownForeground": "{{variant.scheme.foreground}}",
"settings.dropdownBackground": "{{variant.scheme.backgroundAlt}}",
"settings.numberInputForeground": "{{variant.scheme.foreground}}",
"settings.numberInputBackground": "{{variant.scheme.backgroundAlt}}",
"settings.textInputForeground": "{{variant.scheme.foreground}}",
"settings.textInputBackground": "{{variant.scheme.backgroundAlt}}",
"settings.headerForeground": "{{commons.accents.Teal}}"
} }
} }