Merge pull request #163 from LasaleFamine/develop
This commit is contained in:
commit
93b710945f
7 changed files with 5519 additions and 65 deletions
|
@ -2,8 +2,8 @@ import {getAccentableIcons} from '../../helpers/fs';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute, getVariantIcons } from "../../helpers/fs";
|
import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute, getVariantIcons } from "../../helpers/fs";
|
||||||
import { getCurrentThemeIconsID } from "../../helpers/vscode";
|
import { getCurrentThemeIconsID, getCurrentThemeID } from "../../helpers/vscode";
|
||||||
import { isAccent, isMaterialThemeIcons, getThemeSettings, getCustomSettings } from "../../helpers/settings";
|
import { isAccent, isMaterialThemeIcons, getCustomSettings } from "../../helpers/settings";
|
||||||
|
|
||||||
import { CHARSET } from "../../consts/files";
|
import { CHARSET } from "../../consts/files";
|
||||||
import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
|
import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
|
||||||
|
@ -44,11 +44,11 @@ export const THEME_ICONS = () => {
|
||||||
let themeIconsID: string = getCurrentThemeIconsID();
|
let themeIconsID: string = getCurrentThemeIconsID();
|
||||||
|
|
||||||
if (isMaterialThemeIcons(themeIconsID)) {
|
if (isMaterialThemeIcons(themeIconsID)) {
|
||||||
let themeSettings = getThemeSettings();
|
let themeID = getCurrentThemeID();
|
||||||
let customSettings = getCustomSettings();
|
let customSettings = getCustomSettings();
|
||||||
let defaults = getDefaultValues();
|
let defaults = getDefaultValues();
|
||||||
let accentName = customSettings.accent;
|
let accentName = customSettings.accent;
|
||||||
let variantName: string = getVariantFromColor(themeSettings.colorTheme);
|
let variantName: string = getVariantFromColor(themeID);
|
||||||
|
|
||||||
let themeContribute: IPackageJSONThemeIcons = getThemeIconsContribute(themeIconsID);
|
let themeContribute: IPackageJSONThemeIcons = getThemeIconsContribute(themeIconsID);
|
||||||
let theme: IThemeIcons = getThemeIconsByContributeID(themeIconsID);
|
let theme: IThemeIcons = getThemeIconsByContributeID(themeIconsID);
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import * as fs from "fs";
|
|
||||||
import * as vscode from 'vscode';
|
|
||||||
|
|
||||||
import { getAbsolutePath, getDefaultValues, getPackageJSON } from "../../helpers/fs";
|
|
||||||
import { getCustomSettings, setCustomSettings } from "../../helpers/settings";
|
|
||||||
|
|
||||||
import { CHARSET } from "../../consts/files";
|
|
||||||
import { THEME_ICONS } from "../theme-icons/index";
|
|
||||||
import { reloadWindow } from "../../helpers/vscode";
|
|
||||||
|
|
||||||
export const THEME_VARIANT = () => {
|
|
||||||
let defaults = getDefaultValues();
|
|
||||||
let options: string[] = Object.keys(defaults.themeVariants);
|
|
||||||
let packageJSON = getPackageJSON();
|
|
||||||
|
|
||||||
options = options.filter(i => i !== packageJSON.contributes.themes[0].path);
|
|
||||||
|
|
||||||
vscode.window.showQuickPick(options).then((response: string) => {
|
|
||||||
if (!response) return;
|
|
||||||
|
|
||||||
let customSettings = getCustomSettings();
|
|
||||||
let themepath: string = defaults.themeVariants[response];
|
|
||||||
let themeUITheme: string = defaults.themeVariantsUITheme[response];
|
|
||||||
|
|
||||||
// customSettings.themeColours = response;
|
|
||||||
|
|
||||||
packageJSON.contributes.themes[0].path = themepath;
|
|
||||||
packageJSON.contributes.themes[0].uiTheme = themeUITheme;
|
|
||||||
|
|
||||||
fs.writeFile(getAbsolutePath('./package.json'), JSON.stringify(packageJSON, null, 2), { encoding: CHARSET }, (error) => {
|
|
||||||
if (error) {
|
|
||||||
console.trace(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCustomSettings(customSettings).then(() => {
|
|
||||||
THEME_ICONS().then(() => reloadWindow()).catch(error => console.trace(error))
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -2,18 +2,8 @@ import * as vscode from 'vscode';
|
||||||
|
|
||||||
import { IDefaults } from "../interfaces/idefaults";
|
import { IDefaults } from "../interfaces/idefaults";
|
||||||
import { IThemeCustomProperties } from "../interfaces/itheme-custom-properties";
|
import { IThemeCustomProperties } from "../interfaces/itheme-custom-properties";
|
||||||
import { IThemeSettings } from "../interfaces/itheme-settings";
|
|
||||||
import {getPackageJSON} from './fs';
|
import {getPackageJSON} from './fs';
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets theme settings
|
|
||||||
* @export
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
export function getThemeSettings(): IThemeSettings {
|
|
||||||
return vscode.workspace.getConfiguration().get<IThemeSettings>('workbench', {});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets saved accent
|
* Gets saved accent
|
||||||
* @export
|
* @export
|
||||||
|
|
|
@ -33,6 +33,15 @@ export function getCurrentThemeIconsID(): string {
|
||||||
return vscode.workspace.getConfiguration().get<string>('workbench.iconTheme');
|
return vscode.workspace.getConfiguration().get<string>('workbench.iconTheme');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a specific id for icons
|
||||||
|
* @export
|
||||||
|
* @returns {Thenable}
|
||||||
|
*/
|
||||||
|
export function setIconsID(id: string): Thenable<void> {
|
||||||
|
return vscode.workspace.getConfiguration().update('workbench.iconTheme', id, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads current vscode window.
|
* Reloads current vscode window.
|
||||||
* @export
|
* @export
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
export interface IThemeSettings {
|
|
||||||
colorTheme?: string;
|
|
||||||
}
|
|
|
@ -4,25 +4,36 @@ import { IGenericObject } from "./interfaces/igeneric-object";
|
||||||
import { THEME_ACCENTS_SETTER } from "./commands/accents-setter/index";
|
import { THEME_ACCENTS_SETTER } from "./commands/accents-setter/index";
|
||||||
import { THEME_ICONS } from "./commands/theme-icons/index";
|
import { THEME_ICONS } from "./commands/theme-icons/index";
|
||||||
import { shouldShowChangelog, showChangelog } from './helpers/changelog';
|
import { shouldShowChangelog, showChangelog } from './helpers/changelog';
|
||||||
import { reloadWindow } from "./helpers/vscode";
|
import { reloadWindow, getCurrentThemeID, setIconsID } from "./helpers/vscode";
|
||||||
|
|
||||||
enum Commands {
|
enum Commands {
|
||||||
ACCENTS,
|
ACCENTS,
|
||||||
CHANGELOG,
|
CHANGELOG
|
||||||
THEME_ICONS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const OPTIONS: IGenericObject<number> = {
|
const OPTIONS: IGenericObject<number> = {
|
||||||
'🖍 Change accent color': Commands.ACCENTS,
|
'🖍 Change accent color': Commands.ACCENTS,
|
||||||
'🎨 Adapt icons': Commands.THEME_ICONS,
|
|
||||||
'🚧 Show changelog': Commands.CHANGELOG
|
'🚧 Show changelog': Commands.CHANGELOG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isMaterialTheme = (currentTheme: string): boolean =>
|
||||||
|
currentTheme.includes('Material Theme');
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
if (vscode.workspace.getConfiguration().has('materialTheme.cache.workbench.accent')) {
|
if (vscode.workspace.getConfiguration().has('materialTheme.cache.workbench.accent')) {
|
||||||
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.accent', undefined, true);
|
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.accent', undefined, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vscode.workspace.onDidChangeConfiguration(async event => {
|
||||||
|
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
|
||||||
|
const currentTheme = getCurrentThemeID();
|
||||||
|
if (isColorTheme && isMaterialTheme(currentTheme)) {
|
||||||
|
await setIconsID('eq-material-theme-icons');
|
||||||
|
await THEME_ICONS().catch(error => console.trace(error));
|
||||||
|
reloadWindow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (shouldShowChangelog()) {
|
if (shouldShowChangelog()) {
|
||||||
showChangelog();
|
showChangelog();
|
||||||
}
|
}
|
||||||
|
@ -39,9 +50,6 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
case Commands.CHANGELOG:
|
case Commands.CHANGELOG:
|
||||||
showChangelog();
|
showChangelog();
|
||||||
break;
|
break;
|
||||||
case Commands.THEME_ICONS:
|
|
||||||
THEME_ICONS().then(() => reloadWindow()).catch(error => console.trace(error));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue