Fix/custom settings (#237)

* chore: added accents as enum and removed accentPrevious

* chore: removed fixIconsRunning prop and added logic for replacing it

* chore: added accents as enum and removed accentPrevious

* chore: removed fixIconsRunning prop and added logic for replacing it
This commit is contained in:
Alessio Occhipinti 2018-08-16 09:11:38 +02:00 committed by Mattia Astorino
parent 240980fbc1
commit 0a90ac7dd2
5 changed files with 36 additions and 27 deletions

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

@ -1,17 +1,12 @@
import { import {
ConfigurationChangeEvent ConfigurationChangeEvent
} from 'vscode'; } from 'vscode';
import {getCustomSettings, isMaterialThemeIcons, isMaterialTheme} from './settings'; import {isMaterialThemeIcons, isMaterialTheme} from './settings';
import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode'; import {getCurrentThemeIconsID, getCurrentThemeID} from './vscode';
import handleAutoapply from './handle-autoapply'; import handleAutoapply from './handle-autoapply';
const onIconsChanged = () => { const onIconsChanged = () => {
const customSettings = getCustomSettings();
if (customSettings.fixIconsRunning) {
return;
}
const currentIconsTheme = getCurrentThemeIconsID(); const currentIconsTheme = getCurrentThemeIconsID();
return handleAutoapply(isMaterialThemeIcons(currentIconsTheme)); return handleAutoapply(isMaterialThemeIcons(currentIconsTheme));
}; };

View file

@ -66,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,6 +1,4 @@
export interface IThemeCustomProperties { export interface IThemeCustomProperties {
accent?: string; accent?: string;
accentPrevious?: string;
autoApplyIcons?: boolean; autoApplyIcons?: boolean;
fixIconsRunning?: boolean;
} }

View file

@ -85,26 +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 with window reload when needed", "description": "Enable/disable auto-apply of Material Theme icons with window reload when needed",
"default": false "default": false,
"scope": "window"
}, },
"materialTheme.showReloadNotification": { "materialTheme.showReloadNotification": {
"type": "boolean", "type": "boolean",
"description": "Useful when autoApplyIcons is false and you want to be asked to reload the window when needed", "description": "Useful when autoApplyIcons is false and you want to be asked to reload the window when needed",
"default": true "default": true,
}, "scope": "window"
"materialTheme.fixIconsRunning": {
"type": "boolean",
"description": "For checking if the command is currently acting",
"default": false
} }
} }
}, },