diff --git a/packages/extension/src/browser/vscode/contributes/icon.ts b/packages/extension/src/browser/vscode/contributes/icon.ts index d807728483..874e7071e2 100644 --- a/packages/extension/src/browser/vscode/contributes/icon.ts +++ b/packages/extension/src/browser/vscode/contributes/icon.ts @@ -1,7 +1,7 @@ import { Autowired, Injectable } from '@opensumi/di'; import { StaticResourceService } from '@opensumi/ide-core-browser/lib/static-resource/static.definition'; import { ILogger, LifeCyclePhase, URI, localize, path } from '@opensumi/ide-core-common'; -import { IIconService, IThemeContribution } from '@opensumi/ide-theme'; +import { IIconService, IProductIconService, IThemeContribution } from '@opensumi/ide-theme'; import { getIconRegistry } from '@opensumi/ide-theme/lib/common/icon-registry'; import { Contributes, LifeCycle, VSCodeContributePoint } from '../../../common'; @@ -58,14 +58,14 @@ export class IconsContributionPoint extends VSCodeContributePoint { @Autowired(AbstractExtInstanceManagementService) protected readonly extensionManageService: AbstractExtInstanceManagementService; + @Autowired(IProductIconService) + protected readonly productIconService: IProductIconService; + @Autowired() private readonly staticResourceService: StaticResourceService; - @Autowired(IIconService) - protected readonly iconService: IIconService; - @Autowired(ILogger) - logger: ILogger; + private logger: ILogger; private iconRegistry = getIconRegistry(); @@ -114,5 +114,6 @@ export class IconsContributionPoint extends VSCodeContributePoint { } }); } + this.productIconService.updateProductIconThemes(); } } diff --git a/packages/extension/src/browser/vscode/contributes/productIconTheme.ts b/packages/extension/src/browser/vscode/contributes/productIconTheme.ts index be7f00c5cd..211fb45829 100644 --- a/packages/extension/src/browser/vscode/contributes/productIconTheme.ts +++ b/packages/extension/src/browser/vscode/contributes/productIconTheme.ts @@ -7,7 +7,6 @@ import { AbstractExtInstanceManagementService } from '../../types'; export type ThemesSchema = Array; -// TODO 需等待 monaco-colors 初始化完成 才能注册 @Injectable() @Contributes('productIconThemes') @LifeCycle(LifeCyclePhase.Initialize) diff --git a/packages/theme/src/browser/product-icon.service.ts b/packages/theme/src/browser/product-icon.service.ts index cb1838cf82..6b0d49cdff 100644 --- a/packages/theme/src/browser/product-icon.service.ts +++ b/packages/theme/src/browser/product-icon.service.ts @@ -122,7 +122,6 @@ export class ProductIconService extends WithEventBus implements IProductIconServ @OnEvent(ExtensionDidContributes) async onDidExtensionContributes() { await this.updateProductIconThemes(); - this.productIconThemeLoaded.resolve(); } get preferenceThemeId(): string | undefined { @@ -133,7 +132,10 @@ export class ProductIconService extends WithEventBus implements IProductIconServ return this.currentTheme; } - private async updateProductIconThemes() { + /** + * 初始化注册默认主题 + */ + public async updateProductIconThemes() { const themeMap = this.getAvailableThemeInfos().reduce((pre: Map, cur: IconThemeInfo) => { if (!pre.has(cur.themeId)) { pre.set(cur.themeId, cur.name); @@ -153,6 +155,7 @@ export class ProductIconService extends WithEventBus implements IProductIconServ await this.applyTheme(this.preferenceThemeId); } } + this.productIconThemeLoaded.resolve(); } async applyTheme(themeId: string): Promise { diff --git a/packages/theme/src/browser/theme.contribution.ts b/packages/theme/src/browser/theme.contribution.ts index b71d38fdc3..ee53ebfd20 100644 --- a/packages/theme/src/browser/theme.contribution.ts +++ b/packages/theme/src/browser/theme.contribution.ts @@ -68,7 +68,6 @@ export class ThemeContribution implements MenuContribution, CommandContribution, async initialize() { this.registerDefaultColorTheme(); - this.registerDefaultProductIconTheme(); this.registerDefaultTokenStyles(); this.registerDefaultTokenType(); @@ -88,14 +87,6 @@ export class ThemeContribution implements MenuContribution, CommandContribution, } } - private registerDefaultProductIconTheme() { - const themeId = this.preferenceService.get(GeneralSettingsId.ProductIconTheme); - const shouldApplyDefaultThemeId = !themeId; - if (shouldApplyDefaultThemeId) { - this.productIconService.applyTheme(DEFAULT_PRODUCT_ICON_THEME_ID); - } - } - private registerDefaultTokenModifier() { this.semanticTokenRegistry.registerTokenModifier( 'declaration', diff --git a/packages/theme/src/common/theme.service.ts b/packages/theme/src/common/theme.service.ts index 36916369c3..c727385559 100644 --- a/packages/theme/src/common/theme.service.ts +++ b/packages/theme/src/common/theme.service.ts @@ -1,6 +1,6 @@ import { IRawThemeSetting } from 'vscode-textmate'; -import { Deferred, Event, IDisposable, IThemeColor, URI } from '@opensumi/ide-core-common'; +import { Deferred, Event, IDisposable, IThemeColor, MaybePromise, URI } from '@opensumi/ide-core-common'; import { Color } from './color'; import { hc_black, hc_light, vs, vs_dark } from './default-themes'; @@ -146,6 +146,8 @@ export interface IThemeService { export interface IProductIconService { currentThemeId: string; currentTheme: IProductIconTheme; + productIconThemeLoaded: Deferred; + updateProductIconThemes(): MaybePromise; onDidProductIconThemeChange: Event; applyTheme(themeId: string): Promise; registerProductIconThemes(productIconThemesContribution: IThemeContribution[], extPath: URI): void;