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

View file

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

View file

@ -66,7 +66,5 @@ export function setCustomSetting(settingName: string, value: any): Thenable<stri
* Updates accent name
*/
export function updateAccent(accentName: string): Thenable<string> {
const prevAccent = getAccent();
return setCustomSetting('accentPrevious', prevAccent)
.then(() => setCustomSetting('accent', accentName));
return setCustomSetting('accent', accentName);
}

View file

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

View file

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