Skip to content

Commit 84f5780

Browse files
committed
feat: add colorRegistery
1 parent d05f093 commit 84f5780

File tree

12 files changed

+732
-72
lines changed

12 files changed

+732
-72
lines changed

src/extensions/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { ExtendActivityBar } from './activityBar';
22
import { ExtendExplore } from './explore';
33
import { ExtendSearch } from './search';
44
import { ExtendStatusBar } from './statusBar';
5-
6-
const Themes = require('./theme-defaults/package.json');
5+
import { defaultColorThemeExtension } from './theme-defaults';
6+
import { monokaiColorThemeExtension } from './theme-monokai';
7+
import { paleNightColorThemeExtension } from './vscode-palenight-theme';
78

89
/**
910
* Default extensions
@@ -13,5 +14,7 @@ export const defaultExtensions = [
1314
ExtendExplore,
1415
ExtendSearch,
1516
ExtendStatusBar,
16-
Themes,
17+
defaultColorThemeExtension,
18+
monokaiColorThemeExtension,
19+
paleNightColorThemeExtension,
1720
];
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { IColorTheme } from "mo/model/colorTheme";
2+
import { IExtension, IExtensionType } from "mo/model/extension";
3+
4+
const colorThemesExtension: IExtension = require('./package.json');
5+
6+
function initColorTheme() {
7+
8+
try {
9+
10+
if (!colorThemesExtension || !colorThemesExtension.categories?.includes(IExtensionType.Theme)) {
11+
console.error('This is invalid colorTheme extension package!', colorThemesExtension);
12+
}
13+
14+
const themes = colorThemesExtension.contributes?.themes?.map((theme: IColorTheme) => {
15+
if (theme.path) {
16+
const themeDetail = {}; // require(theme.path);
17+
return Object.assign({}, theme, themeDetail)
18+
}
19+
return theme;
20+
});
21+
22+
if (!colorThemesExtension.contributes) {
23+
colorThemesExtension.contributes = { themes: [] };
24+
}
25+
26+
colorThemesExtension.contributes.themes = themes;
27+
} catch (e) {
28+
throw new Error('Load color theme exception:' + e);
29+
}
30+
}
31+
32+
initColorTheme();
33+
34+
export {
35+
colorThemesExtension
36+
}

src/model/theme.ts src/model/colorTheme.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ export interface TokenColor extends Object {
88
settings?: object;
99
}
1010

11-
export interface ITheme {
11+
export interface IColorTheme {
1212
/**
1313
* The id of component, theme will be applied by this ID
1414
*/
1515
id: string;
16+
label: string;
1617
name: string;
18+
uiTheme: string;
19+
path?: string;
1720
colors?: ThemeColor;
1821
tokenColors?: TokenColor[];
1922
/**

src/model/extension.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { IExtensionService } from 'mo/services';
2+
import { IColorTheme } from './colorTheme';
3+
import { IIconTheme } from './iconTheme';
24

35
/**
46
* Defines extension types
57
*/
68
export enum IExtensionType {
7-
Theme = 'themes',
9+
Theme = 'Themes',
810
Normal = 'normal',
911
Settings = 'settings',
1012
Locals = 'locals',
@@ -17,13 +19,17 @@ export enum IContributeType {
1719
Commands = 'commands',
1820
Configuration = 'configuration',
1921
Grammar = 'grammars',
22+
Theme = 'themes',
23+
IconTheme = 'iconThemes',
2024
}
2125

2226
export interface IContribute {
23-
[IContributeType.Languages]: any;
24-
[IContributeType.Commands]: any;
25-
[IContributeType.Configuration]: any;
26-
[IContributeType.Grammar]: any;
27+
[IContributeType.Languages]?: any;
28+
[IContributeType.Commands]?: any;
29+
[IContributeType.Configuration]?: any;
30+
[IContributeType.Grammar]?: any;
31+
[IContributeType.Theme]?: IColorTheme[];
32+
[IContributeType.IconTheme]?: IIconTheme[];
2733
}
2834

2935
/**

src/model/ui.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ITheme } from './theme';
1+
import { IColorTheme } from './colorTheme';
2+
import { IIconTheme } from './iconTheme';
23

34
export interface IUI {
4-
colorTheme?: ITheme;
5-
iconTheme?: ITheme;
5+
colorTheme?: IColorTheme;
6+
iconTheme?: IIconTheme;
67
}

src/provider/molecule.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'mo/style/main.scss';
22
import 'vscode-codicons/dist/codicon.css';
33
import * as React from 'react';
44
import { container } from 'tsyringe';
5-
import { ITheme } from 'mo/model/theme';
5+
import { IColorTheme } from 'mo/model/colorTheme';
66
import { defaultExtensions } from 'mo/extensions';
77
import { IExtension } from 'mo/model/extension';
88
import { ILocalization } from 'mo/model/localization';
@@ -14,7 +14,7 @@ import {
1414
interface Props {
1515
extensions?: IExtension[];
1616
locales?: ILocalization[];
17-
colorTheme?: ITheme[];
17+
colorTheme?: IColorTheme[];
1818
}
1919

2020
export const MoleculeCtx = React.createContext({});

src/services/helper.ts

Whitespace-only changes.

src/services/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import 'reflect-metadata';
22
import { container } from 'tsyringe';
33

44
export * from './extensionService';
5-
export * from './themeService';
5+
export * from './theme/colorThemeService';
66
export * from './workbench';
77

8-
import { ThemeService } from './themeService';
8+
import { ColorThemeService, IColorThemeService } from './theme/colorThemeService';
99
import { ExtensionService, IExtensionService } from './extensionService';
1010
import {
1111
ActivityBarService,
@@ -39,7 +39,7 @@ const statusBarService = container.resolve<IStatusBarService>(StatusBarService);
3939
* The theme service,
4040
* TODO: think about break themeService into ColorTheme and IconTheme
4141
*/
42-
const themeService = container.resolve(ThemeService);
42+
const colorThemeService = container.resolve<IColorThemeService>(ColorThemeService);
4343

4444
/**
4545
* Note: The extension service depends on other workbench services,
@@ -55,5 +55,5 @@ export {
5555
statusBarService,
5656
editorService,
5757
extensionService,
58-
themeService,
58+
colorThemeService,
5959
};

src/services/theme/colorMap.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const ColorMap = new Map<Symbol, string>();
2+
3+
export {
4+
ColorMap
5+
}

0 commit comments

Comments
 (0)