@@ -29,6 +29,8 @@ import {
29
29
isLinux ,
30
30
isWindows ,
31
31
IThemeColor ,
32
+ OnEvent ,
33
+ ExtensionDidContributes ,
32
34
} from '@opensumi/ide-core-common' ;
33
35
import { Autowired , Injectable } from '@opensumi/di' ;
34
36
import { getColorRegistry } from '../common/color-registry' ;
@@ -99,18 +101,42 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService
99
101
this . applyPlatformClass ( ) ;
100
102
}
101
103
104
+ @OnEvent ( ExtensionDidContributes )
105
+ onDidExtensionContributes ( ) {
106
+ const themeMap = this . getAvailableThemeInfos ( ) . reduce ( ( pre : Map < string , string > , cur : ThemeInfo ) => {
107
+ if ( ! pre . has ( cur . themeId ) ) {
108
+ pre . set ( cur . themeId , cur . name ) ;
109
+ }
110
+ return pre ;
111
+ } , new Map ( ) ) ;
112
+
113
+ const themeId = this . preferenceService . get < string > ( COLOR_THEME_SETTING ) ;
114
+ if ( themeId && themeId !== DEFAULT_THEME_ID && themeMap . has ( themeId ) ) {
115
+ this . applyTheme ( themeId ) ;
116
+ } else {
117
+ this . applyTheme ( DEFAULT_THEME_ID ) ;
118
+ }
119
+
120
+ this . preferenceSettings . setEnumLabels ( COLOR_THEME_SETTING , Object . fromEntries ( themeMap . entries ( ) ) ) ;
121
+ }
122
+
102
123
public registerThemes ( themeContributions : ThemeContribution [ ] , extPath : URI ) {
103
124
const disposables = new DisposableCollection ( ) ;
104
125
disposables . push ( {
105
126
dispose : ( ) => this . doSetPreferenceSchema ( ) ,
106
127
} ) ;
128
+ const preferenceThemeId = this . preferenceService . get < string > ( COLOR_THEME_SETTING ) ;
107
129
108
130
themeContributions . forEach ( ( contribution ) => {
109
131
const themeExtContribution = { basePath : extPath , contribution } ;
110
132
const themeId = getThemeId ( contribution ) ;
111
133
112
134
this . themeContributionRegistry . set ( themeId , themeExtContribution ) ;
113
135
136
+ if ( preferenceThemeId === themeId ) {
137
+ this . applyTheme ( preferenceThemeId ) ;
138
+ }
139
+
114
140
disposables . push ( {
115
141
dispose : ( ) => {
116
142
this . themeContributionRegistry . delete ( themeId ) ;
@@ -149,6 +175,7 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService
149
175
const currentThemeType = this . currentTheme . type ;
150
176
151
177
this . toggleBaseThemeClass ( prevThemeType , currentThemeType ) ;
178
+
152
179
this . doApplyTheme ( this . currentTheme ) ;
153
180
}
154
181
@@ -252,22 +279,6 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService
252
279
} ,
253
280
true ,
254
281
) ;
255
-
256
- const themeMap = this . getAvailableThemeInfos ( ) . reduce ( ( pre : Map < string , string > , cur : ThemeInfo ) => {
257
- if ( ! pre . has ( cur . themeId ) ) {
258
- pre . set ( cur . themeId , cur . name ) ;
259
- }
260
- return pre ;
261
- } , new Map ( ) ) ;
262
-
263
- const themeId = this . preferenceService . get < string > ( COLOR_THEME_SETTING ) ;
264
- if ( themeId && themeId !== DEFAULT_THEME_ID && themeMap . has ( themeId ) ) {
265
- this . applyTheme ( themeId ) ;
266
- } else {
267
- this . applyTheme ( DEFAULT_THEME_ID ) ;
268
- }
269
-
270
- this . preferenceSettings . setEnumLabels ( COLOR_THEME_SETTING , Object . fromEntries ( themeMap . entries ( ) ) ) ;
271
282
}
272
283
273
284
private get colorCustomizations ( ) : IColorCustomizations {
0 commit comments