|
4 | 4 | */
|
5 | 5 |
|
6 | 6 | import 'reflect-metadata';
|
7 |
| -import { IColorTheme } from 'mo/model/colorTheme'; |
| 7 | +import { IColorTheme, ColorThemeMode, ColorScheme } from 'mo/model/colorTheme'; |
8 | 8 | import { singleton } from 'tsyringe';
|
9 | 9 | import { editor as monacoEditor } from 'mo/monaco';
|
10 | 10 | import { applyStyleSheetRules } from 'mo/common/css';
|
11 | 11 | import { getThemeData, convertToCSSVars } from './helper';
|
12 | 12 | import logger from 'mo/common/logger';
|
13 | 13 | import { prefixClaName } from 'mo/common/className';
|
14 |
| -import { searchById } from 'mo/common/utils'; |
| 14 | +import { searchById, colorLightOrDark } from 'mo/common/utils'; |
15 | 15 |
|
16 | 16 | export interface IColorThemeService {
|
17 | 17 | /**
|
@@ -53,6 +53,10 @@ export interface IColorThemeService {
|
53 | 53 | * Reset theme
|
54 | 54 | */
|
55 | 55 | reset(): void;
|
| 56 | + /** |
| 57 | + * Get the mode('dark' or 'light') of the current Color Theme |
| 58 | + */ |
| 59 | + getColorThemeMode(): ColorThemeMode; |
56 | 60 | }
|
57 | 61 |
|
58 | 62 | /**
|
@@ -153,4 +157,27 @@ export class ColorThemeService implements IColorThemeService {
|
153 | 157 | this.colorThemes = [BuiltInColorTheme];
|
154 | 158 | this.setTheme(BuiltInColorTheme.id);
|
155 | 159 | }
|
| 160 | + |
| 161 | + public getColorThemeMode(): ColorThemeMode { |
| 162 | + const { colors, type } = this.colorTheme; |
| 163 | + |
| 164 | + // Try to get colorThemeMode from type |
| 165 | + if (type === ColorScheme.DARK || type === ColorScheme.HIGH_CONTRAST) { |
| 166 | + return ColorThemeMode.dark; |
| 167 | + } else if (type === ColorScheme.LIGHT) { |
| 168 | + return ColorThemeMode.light; |
| 169 | + } |
| 170 | + |
| 171 | + // Try to get colorThemeMode from background color |
| 172 | + const background = |
| 173 | + colors?.['editor.background'] || |
| 174 | + colors?.['tab.activeBackground'] || |
| 175 | + colors?.['molecule.welcomeBackground']; |
| 176 | + if (background) { |
| 177 | + return colorLightOrDark(background) as ColorThemeMode; |
| 178 | + } |
| 179 | + |
| 180 | + // Default dark |
| 181 | + return ColorThemeMode.dark; |
| 182 | + } |
156 | 183 | }
|
0 commit comments