Skip to content

Commit 481089a

Browse files
authored
fix: product icons contribution not initial (#3469)
1 parent 0bb0671 commit 481089a

5 files changed

Lines changed: 14 additions & 18 deletions

File tree

packages/extension/src/browser/vscode/contributes/icon.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Autowired, Injectable } from '@opensumi/di';
22
import { StaticResourceService } from '@opensumi/ide-core-browser/lib/static-resource/static.definition';
33
import { ILogger, LifeCyclePhase, URI, localize, path } from '@opensumi/ide-core-common';
4-
import { IIconService, IThemeContribution } from '@opensumi/ide-theme';
4+
import { IIconService, IProductIconService, IThemeContribution } from '@opensumi/ide-theme';
55
import { getIconRegistry } from '@opensumi/ide-theme/lib/common/icon-registry';
66

77
import { Contributes, LifeCycle, VSCodeContributePoint } from '../../../common';
@@ -58,14 +58,14 @@ export class IconsContributionPoint extends VSCodeContributePoint<IconSchema> {
5858
@Autowired(AbstractExtInstanceManagementService)
5959
protected readonly extensionManageService: AbstractExtInstanceManagementService;
6060

61+
@Autowired(IProductIconService)
62+
protected readonly productIconService: IProductIconService;
63+
6164
@Autowired()
6265
private readonly staticResourceService: StaticResourceService;
6366

64-
@Autowired(IIconService)
65-
protected readonly iconService: IIconService;
66-
6767
@Autowired(ILogger)
68-
logger: ILogger;
68+
private logger: ILogger;
6969

7070
private iconRegistry = getIconRegistry();
7171

@@ -114,5 +114,6 @@ export class IconsContributionPoint extends VSCodeContributePoint<IconSchema> {
114114
}
115115
});
116116
}
117+
this.productIconService.updateProductIconThemes();
117118
}
118119
}

packages/extension/src/browser/vscode/contributes/productIconTheme.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { AbstractExtInstanceManagementService } from '../../types';
77

88
export type ThemesSchema = Array<IThemeContribution>;
99

10-
// TODO 需等待 monaco-colors 初始化完成 才能注册
1110
@Injectable()
1211
@Contributes('productIconThemes')
1312
@LifeCycle(LifeCyclePhase.Initialize)

packages/theme/src/browser/product-icon.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export class ProductIconService extends WithEventBus implements IProductIconServ
122122
@OnEvent(ExtensionDidContributes)
123123
async onDidExtensionContributes() {
124124
await this.updateProductIconThemes();
125-
this.productIconThemeLoaded.resolve();
126125
}
127126

128127
get preferenceThemeId(): string | undefined {
@@ -133,7 +132,10 @@ export class ProductIconService extends WithEventBus implements IProductIconServ
133132
return this.currentTheme;
134133
}
135134

136-
private async updateProductIconThemes() {
135+
/**
136+
* 初始化注册默认主题
137+
*/
138+
public async updateProductIconThemes() {
137139
const themeMap = this.getAvailableThemeInfos().reduce((pre: Map<string, string>, cur: IconThemeInfo) => {
138140
if (!pre.has(cur.themeId)) {
139141
pre.set(cur.themeId, cur.name);
@@ -153,6 +155,7 @@ export class ProductIconService extends WithEventBus implements IProductIconServ
153155
await this.applyTheme(this.preferenceThemeId);
154156
}
155157
}
158+
this.productIconThemeLoaded.resolve();
156159
}
157160

158161
async applyTheme(themeId: string): Promise<void> {

packages/theme/src/browser/theme.contribution.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class ThemeContribution implements MenuContribution, CommandContribution,
6868

6969
async initialize() {
7070
this.registerDefaultColorTheme();
71-
this.registerDefaultProductIconTheme();
7271

7372
this.registerDefaultTokenStyles();
7473
this.registerDefaultTokenType();
@@ -88,14 +87,6 @@ export class ThemeContribution implements MenuContribution, CommandContribution,
8887
}
8988
}
9089

91-
private registerDefaultProductIconTheme() {
92-
const themeId = this.preferenceService.get<string>(GeneralSettingsId.ProductIconTheme);
93-
const shouldApplyDefaultThemeId = !themeId;
94-
if (shouldApplyDefaultThemeId) {
95-
this.productIconService.applyTheme(DEFAULT_PRODUCT_ICON_THEME_ID);
96-
}
97-
}
98-
9990
private registerDefaultTokenModifier() {
10091
this.semanticTokenRegistry.registerTokenModifier(
10192
'declaration',

packages/theme/src/common/theme.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IRawThemeSetting } from 'vscode-textmate';
22

3-
import { Deferred, Event, IDisposable, IThemeColor, URI } from '@opensumi/ide-core-common';
3+
import { Deferred, Event, IDisposable, IThemeColor, MaybePromise, URI } from '@opensumi/ide-core-common';
44

55
import { Color } from './color';
66
import { hc_black, hc_light, vs, vs_dark } from './default-themes';
@@ -146,6 +146,8 @@ export interface IThemeService {
146146
export interface IProductIconService {
147147
currentThemeId: string;
148148
currentTheme: IProductIconTheme;
149+
productIconThemeLoaded: Deferred<void>;
150+
updateProductIconThemes(): MaybePromise<void>;
149151
onDidProductIconThemeChange: Event<IProductIconTheme>;
150152
applyTheme(themeId: string): Promise<void>;
151153
registerProductIconThemes(productIconThemesContribution: IThemeContribution[], extPath: URI): void;

0 commit comments

Comments
 (0)