diff --git a/packages/core-common/src/types/extension.ts b/packages/core-common/src/types/extension.ts index 7bd9abcc95..6ad998c577 100644 --- a/packages/core-common/src/types/extension.ts +++ b/packages/core-common/src/types/extension.ts @@ -83,3 +83,5 @@ export interface IExtensionActivateEventPayload { } export class ExtensionActivateEvent extends BasicEvent {} + +export class ExtensionDidContributes extends BasicEvent {} diff --git a/packages/extension/src/browser/extension.service.ts b/packages/extension/src/browser/extension.service.ts index 8a537a5e87..a13eb100b8 100644 --- a/packages/extension/src/browser/extension.service.ts +++ b/packages/extension/src/browser/extension.service.ts @@ -3,7 +3,7 @@ import { IWorkspaceService } from '@opensumi/ide-workspace'; import { IDialogService, IMessageService } from '@opensumi/ide-overlay'; import { IProgressService } from '@opensumi/ide-core-browser/lib/progress'; import { IExtensionStorageService } from '@opensumi/ide-extension-storage'; -import { localize, OnEvent, WithEventBus, ProgressLocation } from '@opensumi/ide-core-common'; +import { localize, OnEvent, WithEventBus, ProgressLocation, ExtensionDidContributes } from '@opensumi/ide-core-common'; import { FileSearchServicePath, IFileSearchService } from '@opensumi/ide-file-search/lib/common'; import { AppConfig, @@ -474,6 +474,7 @@ export class ExtensionServiceImpl extends WithEventBus implements ExtensionServi await this.activationEventService.fireEvent('onCommand', command); return args; }); + this.eventBus.fire(new ExtensionDidContributes()); } /** diff --git a/packages/theme/src/browser/theme.contribution.ts b/packages/theme/src/browser/theme.contribution.ts index 42d3aa0c7d..2a3013b7e9 100644 --- a/packages/theme/src/browser/theme.contribution.ts +++ b/packages/theme/src/browser/theme.contribution.ts @@ -59,18 +59,6 @@ export class ThemeContribution implements MenuContribution, CommandContribution, this.registerDefaultTokenStyles(); this.registerDefaultTokenType(); this.registerDefaultTokenModifier(); - - this.initializeDefaultTheme(); - } - - private initializeDefaultTheme() { - const globalProvider = this.preferenceService.getProvider(PreferenceScope.User); - if (globalProvider) { - const themeId = globalProvider.get(COLOR_THEME_SETTING); - if (!themeId || themeId === DEFAULT_THEME_ID) { - this.themeService.applyTheme(DEFAULT_THEME_ID); - } - } } private registerDefaultTokenModifier() { diff --git a/packages/theme/src/browser/workbench.theme.service.ts b/packages/theme/src/browser/workbench.theme.service.ts index 3d3dd2ffa2..a8035aaf13 100644 --- a/packages/theme/src/browser/workbench.theme.service.ts +++ b/packages/theme/src/browser/workbench.theme.service.ts @@ -29,6 +29,8 @@ import { isLinux, isWindows, IThemeColor, + OnEvent, + ExtensionDidContributes, } from '@opensumi/ide-core-common'; import { Autowired, Injectable } from '@opensumi/di'; import { getColorRegistry } from '../common/color-registry'; @@ -99,11 +101,31 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService this.applyPlatformClass(); } + @OnEvent(ExtensionDidContributes) + onDidExtensionContributes() { + const themeMap = this.getAvailableThemeInfos().reduce((pre: Map, cur: ThemeInfo) => { + if (!pre.has(cur.themeId)) { + pre.set(cur.themeId, cur.name); + } + return pre; + }, new Map()); + + const themeId = this.preferenceService.get(COLOR_THEME_SETTING); + if (themeId && themeId !== DEFAULT_THEME_ID && themeMap.has(themeId)) { + this.applyTheme(themeId); + } else { + this.applyTheme(DEFAULT_THEME_ID); + } + + this.preferenceSettings.setEnumLabels(COLOR_THEME_SETTING, Object.fromEntries(themeMap.entries())); + } + public registerThemes(themeContributions: ThemeContribution[], extPath: URI) { const disposables = new DisposableCollection(); disposables.push({ dispose: () => this.doSetPreferenceSchema(), }); + const preferenceThemeId = this.preferenceService.get(COLOR_THEME_SETTING); themeContributions.forEach((contribution) => { const themeExtContribution = { basePath: extPath, contribution }; @@ -111,6 +133,10 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService this.themeContributionRegistry.set(themeId, themeExtContribution); + if (preferenceThemeId === themeId) { + this.applyTheme(preferenceThemeId); + } + disposables.push({ dispose: () => { this.themeContributionRegistry.delete(themeId); @@ -149,6 +175,7 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService const currentThemeType = this.currentTheme.type; this.toggleBaseThemeClass(prevThemeType, currentThemeType); + this.doApplyTheme(this.currentTheme); } @@ -252,22 +279,6 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService }, true, ); - - const themeMap = this.getAvailableThemeInfos().reduce((pre: Map, cur: ThemeInfo) => { - if (!pre.has(cur.themeId)) { - pre.set(cur.themeId, cur.name); - } - return pre; - }, new Map()); - - const themeId = this.preferenceService.get(COLOR_THEME_SETTING); - if (themeId && themeId !== DEFAULT_THEME_ID && themeMap.has(themeId)) { - this.applyTheme(themeId); - } else { - this.applyTheme(DEFAULT_THEME_ID); - } - - this.preferenceSettings.setEnumLabels(COLOR_THEME_SETTING, Object.fromEntries(themeMap.entries())); } private get colorCustomizations(): IColorCustomizations {