@codingame/monaco-vscode-theme-service-override 3.2.3 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,757 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
3
- import { isUndefined, isString } from 'vscode/vscode/vs/base/common/types';
4
- import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
5
- import { ThemeSettingDefaults, COLOR_THEME_LIGHT_INITIAL_COLORS, COLOR_THEME_DARK_INITIAL_COLORS, ThemeSettings, ExtensionData, VS_DARK_THEME, VS_LIGHT_THEME, VS_HC_THEME, VS_HC_LIGHT_THEME } from 'vscode/vscode/vs/workbench/services/themes/common/workbenchThemeService';
6
- import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
7
- import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
8
- import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
9
- import { onUnexpectedError } from 'vscode/vscode/vs/base/common/errors';
10
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
11
- import { ColorThemeData } from '../common/colorThemeData.js';
12
- import { Extensions } from 'vscode/vscode/vs/platform/theme/common/themeService';
13
- import { Emitter } from 'vscode/vscode/vs/base/common/event';
14
- import { registerFileIconThemeSchemas } from '../common/fileIconThemeSchema.js';
15
- import { dispose } from 'vscode/vscode/vs/base/common/lifecycle';
16
- import { FileIconThemeData, FileIconThemeLoader } from './fileIconThemeData.js';
17
- import { createStyleSheet } from 'vscode/vscode/vs/base/browser/dom';
18
- import { IBrowserWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/browser/environmentService';
19
- import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
20
- import { joinPath, isEqual } from 'vscode/vscode/vs/base/common/resources';
21
- import { registerColorThemeSchemas } from '../common/colorThemeSchema.js';
22
- import { getRemoteAuthority } from 'vscode/vscode/vs/platform/remote/common/remoteHosts';
23
- import { IWorkbenchLayoutService } from 'vscode/vscode/vs/workbench/services/layout/browser/layoutService';
24
- import { IExtensionResourceLoaderService } from 'vscode/vscode/vs/platform/extensionResourceLoader/common/extensionResourceLoader';
25
- import { registerColorThemeExtensionPoint, registerFileIconThemeExtensionPoint, registerProductIconThemeExtensionPoint, ThemeRegistry } from '../common/themeExtensionPoints.js';
26
- import { ThemeConfiguration, updateColorThemeConfigurationSchemas, updateFileIconThemeConfigurationSchemas, updateProductIconThemeConfigurationSchemas } from '../common/themeConfiguration.js';
27
- import { ProductIconThemeData, DEFAULT_PRODUCT_ICON_THEME_ID } from './productIconThemeData.js';
28
- import { registerProductIconThemeSchemas } from '../common/productIconThemeSchema.js';
29
- import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
30
- import { isWeb } from 'vscode/vscode/vs/base/common/platform';
31
- import { ColorScheme } from 'vscode/vscode/vs/platform/theme/common/theme';
32
- import { IHostColorSchemeService } from 'vscode/vscode/vs/workbench/services/themes/common/hostColorSchemeService';
33
- import { Sequencer, RunOnceScheduler } from 'vscode/vscode/vs/base/common/async';
34
- import { IUserDataInitializationService } from 'vscode/vscode/vs/workbench/services/userData/browser/userDataInit';
35
- import { getIconsStyleSheet } from 'vscode/vscode/vs/platform/theme/browser/iconsStyleSheet';
36
- import { getColorRegistry, asCssVariableName } from 'vscode/vscode/vs/platform/theme/common/colorRegistry';
37
- import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
38
- import { mainWindow } from 'vscode/vscode/vs/base/browser/window';
39
-
40
- const PERSISTED_OS_COLOR_SCHEME = 'osColorScheme';
41
- const PERSISTED_OS_COLOR_SCHEME_SCOPE = -1 ;
42
- const defaultThemeExtensionId = 'vscode-theme-defaults';
43
- const DEFAULT_FILE_ICON_THEME_ID = 'vscode.vscode-theme-seti-vs-seti';
44
- const fileIconsEnabledClass = 'file-icons-enabled';
45
- const colorThemeRulesClassName = 'contributedColorTheme';
46
- const fileIconThemeRulesClassName = 'contributedFileIconTheme';
47
- const productIconThemeRulesClassName = 'contributedProductIconTheme';
48
- const themingRegistry = ( Registry.as(Extensions.ThemingContribution));
49
- function validateThemeId(theme) {
50
- switch (theme) {
51
- case VS_LIGHT_THEME: return `vs ${defaultThemeExtensionId}-themes-light_vs-json`;
52
- case VS_DARK_THEME: return `vs-dark ${defaultThemeExtensionId}-themes-dark_vs-json`;
53
- case VS_HC_THEME: return `hc-black ${defaultThemeExtensionId}-themes-hc_black-json`;
54
- case VS_HC_LIGHT_THEME: return `hc-light ${defaultThemeExtensionId}-themes-hc_light-json`;
55
- }
56
- return theme;
57
- }
58
- const colorThemesExtPoint = registerColorThemeExtensionPoint();
59
- const fileIconThemesExtPoint = registerFileIconThemeExtensionPoint();
60
- const productIconThemesExtPoint = registerProductIconThemeExtensionPoint();
61
- let WorkbenchThemeService = class WorkbenchThemeService {
62
- constructor(extensionService, storageService, configurationService, telemetryService, environmentService, fileService, extensionResourceLoaderService, layoutService, logService, hostColorService, userDataInitializationService, languageService) {
63
- this.storageService = storageService;
64
- this.configurationService = configurationService;
65
- this.telemetryService = telemetryService;
66
- this.environmentService = environmentService;
67
- this.extensionResourceLoaderService = extensionResourceLoaderService;
68
- this.logService = logService;
69
- this.hostColorService = hostColorService;
70
- this.userDataInitializationService = userDataInitializationService;
71
- this.hasDefaultUpdated = false;
72
- this.themeExtensionsActivated = ( new Map());
73
- this.container = layoutService.mainContainer;
74
- this.settings = ( new ThemeConfiguration(configurationService));
75
- this.colorThemeRegistry = ( new ThemeRegistry(colorThemesExtPoint, ColorThemeData.fromExtensionTheme));
76
- this.colorThemeWatcher = ( new ThemeFileWatcher(fileService, environmentService, this.reloadCurrentColorTheme.bind(this)));
77
- this.onColorThemeChange = ( new Emitter({ leakWarningThreshold: 400 }));
78
- this.currentColorTheme = ColorThemeData.createUnloadedTheme('');
79
- this.colorThemeSequencer = ( new Sequencer());
80
- this.fileIconThemeWatcher = ( new ThemeFileWatcher(
81
- fileService,
82
- environmentService,
83
- this.reloadCurrentFileIconTheme.bind(this)
84
- ));
85
- this.fileIconThemeRegistry = ( new ThemeRegistry(
86
- fileIconThemesExtPoint,
87
- FileIconThemeData.fromExtensionTheme,
88
- true,
89
- FileIconThemeData.noIconTheme
90
- ));
91
- this.fileIconThemeLoader = ( new FileIconThemeLoader(extensionResourceLoaderService, languageService));
92
- this.onFileIconThemeChange = ( new Emitter({ leakWarningThreshold: 400 }));
93
- this.currentFileIconTheme = FileIconThemeData.createUnloadedTheme('');
94
- this.fileIconThemeSequencer = ( new Sequencer());
95
- this.productIconThemeWatcher = ( new ThemeFileWatcher(
96
- fileService,
97
- environmentService,
98
- this.reloadCurrentProductIconTheme.bind(this)
99
- ));
100
- this.productIconThemeRegistry = ( new ThemeRegistry(
101
- productIconThemesExtPoint,
102
- ProductIconThemeData.fromExtensionTheme,
103
- true,
104
- ProductIconThemeData.defaultTheme
105
- ));
106
- this.onProductIconThemeChange = ( new Emitter());
107
- this.currentProductIconTheme = ProductIconThemeData.createUnloadedTheme('');
108
- this.productIconThemeSequencer = ( new Sequencer());
109
- let themeData = ColorThemeData.fromStorageData(this.storageService);
110
- const colorThemeSetting = this.settings.colorTheme;
111
- if (themeData && colorThemeSetting !== themeData.settingsId && this.settings.isDefaultColorTheme()) {
112
- this.hasDefaultUpdated = themeData.settingsId === ThemeSettingDefaults.COLOR_THEME_DARK_OLD || themeData.settingsId === ThemeSettingDefaults.COLOR_THEME_LIGHT_OLD;
113
- themeData = undefined;
114
- }
115
- const preferredColorScheme = this.getPreferredColorScheme();
116
- const defaultColorMap = colorThemeSetting === ThemeSettingDefaults.COLOR_THEME_LIGHT ? COLOR_THEME_LIGHT_INITIAL_COLORS : colorThemeSetting === ThemeSettingDefaults.COLOR_THEME_DARK ? COLOR_THEME_DARK_INITIAL_COLORS : undefined;
117
- if (preferredColorScheme && themeData?.type !== preferredColorScheme && this.storageService.get(PERSISTED_OS_COLOR_SCHEME, PERSISTED_OS_COLOR_SCHEME_SCOPE) !== preferredColorScheme) {
118
- themeData = ColorThemeData.createUnloadedThemeForThemeType(preferredColorScheme, undefined);
119
- }
120
- if (!themeData) {
121
- const initialColorTheme = environmentService.options?.initialColorTheme;
122
- if (initialColorTheme) {
123
- themeData = ColorThemeData.createUnloadedThemeForThemeType(initialColorTheme.themeType, initialColorTheme.colors ?? defaultColorMap);
124
- }
125
- }
126
- if (!themeData) {
127
- themeData = ColorThemeData.createUnloadedThemeForThemeType(isWeb ? ColorScheme.LIGHT : ColorScheme.DARK, defaultColorMap);
128
- }
129
- themeData.setCustomizations(this.settings);
130
- this.applyTheme(themeData, undefined, true);
131
- const fileIconData = FileIconThemeData.fromStorageData(this.storageService);
132
- if (fileIconData) {
133
- this.applyAndSetFileIconTheme(fileIconData, true);
134
- }
135
- const productIconData = ProductIconThemeData.fromStorageData(this.storageService);
136
- if (productIconData) {
137
- this.applyAndSetProductIconTheme(productIconData, true);
138
- }
139
- extensionService.whenInstalledExtensionsRegistered().then(_ => {
140
- this.installConfigurationListener();
141
- this.installPreferredSchemeListener();
142
- this.installRegistryListeners();
143
- this.initialize().catch(onUnexpectedError);
144
- });
145
- const codiconStyleSheet = createStyleSheet();
146
- codiconStyleSheet.id = 'codiconStyles';
147
- const iconsStyleSheet = getIconsStyleSheet(this);
148
- function updateAll() {
149
- codiconStyleSheet.textContent = iconsStyleSheet.getCSS();
150
- }
151
- const delayer = ( new RunOnceScheduler(updateAll, 0));
152
- iconsStyleSheet.onDidChange(() => delayer.schedule());
153
- delayer.schedule();
154
- }
155
- initialize() {
156
- const extDevLocs = this.environmentService.extensionDevelopmentLocationURI;
157
- const extDevLoc = extDevLocs && extDevLocs.length === 1 ? extDevLocs[0] : undefined;
158
- const initializeColorTheme = async () => {
159
- const devThemes = this.colorThemeRegistry.findThemeByExtensionLocation(extDevLoc);
160
- if (devThemes.length) {
161
- const matchedColorTheme = devThemes.find(theme => theme.type === this.currentColorTheme.type);
162
- return this.setColorTheme(matchedColorTheme ? matchedColorTheme.id : devThemes[0].id, undefined);
163
- }
164
- const preferredColorScheme = this.getPreferredColorScheme();
165
- const prevScheme = this.storageService.get(PERSISTED_OS_COLOR_SCHEME, PERSISTED_OS_COLOR_SCHEME_SCOPE);
166
- if (preferredColorScheme !== prevScheme) {
167
- this.storageService.store(PERSISTED_OS_COLOR_SCHEME, preferredColorScheme, PERSISTED_OS_COLOR_SCHEME_SCOPE, 0 );
168
- if (preferredColorScheme && this.currentColorTheme.type !== preferredColorScheme) {
169
- return this.applyPreferredColorTheme(preferredColorScheme);
170
- }
171
- }
172
- let theme = this.colorThemeRegistry.findThemeBySettingsId(this.settings.colorTheme, undefined);
173
- if (!theme) {
174
- await this.userDataInitializationService.whenInitializationFinished();
175
- const fallbackTheme = this.currentColorTheme.type === ColorScheme.LIGHT ? ThemeSettingDefaults.COLOR_THEME_LIGHT : ThemeSettingDefaults.COLOR_THEME_DARK;
176
- theme = this.colorThemeRegistry.findThemeBySettingsId(this.settings.colorTheme, fallbackTheme);
177
- }
178
- return this.setColorTheme(theme && theme.id, undefined);
179
- };
180
- const initializeFileIconTheme = async () => {
181
- const devThemes = this.fileIconThemeRegistry.findThemeByExtensionLocation(extDevLoc);
182
- if (devThemes.length) {
183
- return this.setFileIconTheme(devThemes[0].id, 8 );
184
- }
185
- let theme = this.fileIconThemeRegistry.findThemeBySettingsId(this.settings.fileIconTheme);
186
- if (!theme) {
187
- await this.userDataInitializationService.whenInitializationFinished();
188
- theme = this.fileIconThemeRegistry.findThemeBySettingsId(this.settings.fileIconTheme);
189
- }
190
- return this.setFileIconTheme(theme ? theme.id : DEFAULT_FILE_ICON_THEME_ID, undefined);
191
- };
192
- const initializeProductIconTheme = async () => {
193
- const devThemes = this.productIconThemeRegistry.findThemeByExtensionLocation(extDevLoc);
194
- if (devThemes.length) {
195
- return this.setProductIconTheme(devThemes[0].id, 8 );
196
- }
197
- let theme = this.productIconThemeRegistry.findThemeBySettingsId(this.settings.productIconTheme);
198
- if (!theme) {
199
- await this.userDataInitializationService.whenInitializationFinished();
200
- theme = this.productIconThemeRegistry.findThemeBySettingsId(this.settings.productIconTheme);
201
- }
202
- return this.setProductIconTheme(theme ? theme.id : DEFAULT_PRODUCT_ICON_THEME_ID, undefined);
203
- };
204
- return Promise.all([initializeColorTheme(), initializeFileIconTheme(), initializeProductIconTheme()]);
205
- }
206
- installConfigurationListener() {
207
- this.configurationService.onDidChangeConfiguration(e => {
208
- let lazyPreferredColorScheme = null;
209
- const getPreferredColorScheme = () => {
210
- if (lazyPreferredColorScheme === null) {
211
- lazyPreferredColorScheme = this.getPreferredColorScheme();
212
- }
213
- return lazyPreferredColorScheme;
214
- };
215
- if (e.affectsConfiguration(ThemeSettings.COLOR_THEME)) {
216
- this.restoreColorTheme();
217
- }
218
- if (e.affectsConfiguration(ThemeSettings.DETECT_COLOR_SCHEME) || e.affectsConfiguration(ThemeSettings.DETECT_HC)) {
219
- this.handlePreferredSchemeUpdated();
220
- }
221
- if (e.affectsConfiguration(ThemeSettings.PREFERRED_DARK_THEME) && getPreferredColorScheme() === ColorScheme.DARK) {
222
- this.applyPreferredColorTheme(ColorScheme.DARK);
223
- }
224
- if (e.affectsConfiguration(ThemeSettings.PREFERRED_LIGHT_THEME) && getPreferredColorScheme() === ColorScheme.LIGHT) {
225
- this.applyPreferredColorTheme(ColorScheme.LIGHT);
226
- }
227
- if (e.affectsConfiguration(ThemeSettings.PREFERRED_HC_DARK_THEME) && getPreferredColorScheme() === ColorScheme.HIGH_CONTRAST_DARK) {
228
- this.applyPreferredColorTheme(ColorScheme.HIGH_CONTRAST_DARK);
229
- }
230
- if (e.affectsConfiguration(ThemeSettings.PREFERRED_HC_LIGHT_THEME) && getPreferredColorScheme() === ColorScheme.HIGH_CONTRAST_LIGHT) {
231
- this.applyPreferredColorTheme(ColorScheme.HIGH_CONTRAST_LIGHT);
232
- }
233
- if (e.affectsConfiguration(ThemeSettings.FILE_ICON_THEME)) {
234
- this.restoreFileIconTheme();
235
- }
236
- if (e.affectsConfiguration(ThemeSettings.PRODUCT_ICON_THEME)) {
237
- this.restoreProductIconTheme();
238
- }
239
- if (this.currentColorTheme) {
240
- let hasColorChanges = false;
241
- if (e.affectsConfiguration(ThemeSettings.COLOR_CUSTOMIZATIONS)) {
242
- this.currentColorTheme.setCustomColors(this.settings.colorCustomizations);
243
- hasColorChanges = true;
244
- }
245
- if (e.affectsConfiguration(ThemeSettings.TOKEN_COLOR_CUSTOMIZATIONS)) {
246
- this.currentColorTheme.setCustomTokenColors(this.settings.tokenColorCustomizations);
247
- hasColorChanges = true;
248
- }
249
- if (e.affectsConfiguration(ThemeSettings.SEMANTIC_TOKEN_COLOR_CUSTOMIZATIONS)) {
250
- this.currentColorTheme.setCustomSemanticTokenColors(this.settings.semanticTokenColorCustomizations);
251
- hasColorChanges = true;
252
- }
253
- if (hasColorChanges) {
254
- this.updateDynamicCSSRules(this.currentColorTheme);
255
- this.onColorThemeChange.fire(this.currentColorTheme);
256
- }
257
- }
258
- });
259
- }
260
- installRegistryListeners() {
261
- let prevColorId = undefined;
262
- this.colorThemeRegistry.onDidChange(async (event) => {
263
- updateColorThemeConfigurationSchemas(event.themes);
264
- if (await this.restoreColorTheme()) {
265
- if (this.currentColorTheme.settingsId === ThemeSettingDefaults.COLOR_THEME_DARK && !isUndefined(prevColorId) && (await this.colorThemeRegistry.findThemeById(prevColorId))) {
266
- await this.setColorTheme(prevColorId, 'auto');
267
- prevColorId = undefined;
268
- }
269
- else if (( event.added.some(t => t.settingsId === this.currentColorTheme.settingsId))) {
270
- await this.reloadCurrentColorTheme();
271
- }
272
- }
273
- else if (( event.removed.some(t => t.settingsId === this.currentColorTheme.settingsId))) {
274
- prevColorId = this.currentColorTheme.id;
275
- const defaultTheme = this.colorThemeRegistry.findThemeBySettingsId(ThemeSettingDefaults.COLOR_THEME_DARK);
276
- await this.setColorTheme(defaultTheme, 'auto');
277
- }
278
- });
279
- let prevFileIconId = undefined;
280
- this.fileIconThemeRegistry.onDidChange(async (event) => {
281
- updateFileIconThemeConfigurationSchemas(event.themes);
282
- if (await this.restoreFileIconTheme()) {
283
- if (this.currentFileIconTheme.id === DEFAULT_FILE_ICON_THEME_ID && !isUndefined(prevFileIconId) && this.fileIconThemeRegistry.findThemeById(prevFileIconId)) {
284
- await this.setFileIconTheme(prevFileIconId, 'auto');
285
- prevFileIconId = undefined;
286
- }
287
- else if (( event.added.some(t => t.settingsId === this.currentFileIconTheme.settingsId))) {
288
- await this.reloadCurrentFileIconTheme();
289
- }
290
- }
291
- else if (( event.removed.some(t => t.settingsId === this.currentFileIconTheme.settingsId))) {
292
- prevFileIconId = this.currentFileIconTheme.id;
293
- await this.setFileIconTheme(DEFAULT_FILE_ICON_THEME_ID, 'auto');
294
- }
295
- });
296
- let prevProductIconId = undefined;
297
- this.productIconThemeRegistry.onDidChange(async (event) => {
298
- updateProductIconThemeConfigurationSchemas(event.themes);
299
- if (await this.restoreProductIconTheme()) {
300
- if (this.currentProductIconTheme.id === DEFAULT_PRODUCT_ICON_THEME_ID && !isUndefined(prevProductIconId) && this.productIconThemeRegistry.findThemeById(prevProductIconId)) {
301
- await this.setProductIconTheme(prevProductIconId, 'auto');
302
- prevProductIconId = undefined;
303
- }
304
- else if (( event.added.some(t => t.settingsId === this.currentProductIconTheme.settingsId))) {
305
- await this.reloadCurrentProductIconTheme();
306
- }
307
- }
308
- else if (( event.removed.some(t => t.settingsId === this.currentProductIconTheme.settingsId))) {
309
- prevProductIconId = this.currentProductIconTheme.id;
310
- await this.setProductIconTheme(DEFAULT_PRODUCT_ICON_THEME_ID, 'auto');
311
- }
312
- });
313
- return Promise.all([this.getColorThemes(), this.getFileIconThemes(), this.getProductIconThemes()]).then(([ct, fit, pit]) => {
314
- updateColorThemeConfigurationSchemas(ct);
315
- updateFileIconThemeConfigurationSchemas(fit);
316
- updateProductIconThemeConfigurationSchemas(pit);
317
- });
318
- }
319
- installPreferredSchemeListener() {
320
- this.hostColorService.onDidChangeColorScheme(() => this.handlePreferredSchemeUpdated());
321
- }
322
- async handlePreferredSchemeUpdated() {
323
- const scheme = this.getPreferredColorScheme();
324
- const prevScheme = this.storageService.get(PERSISTED_OS_COLOR_SCHEME, PERSISTED_OS_COLOR_SCHEME_SCOPE);
325
- if (scheme !== prevScheme) {
326
- this.storageService.store(PERSISTED_OS_COLOR_SCHEME, scheme, PERSISTED_OS_COLOR_SCHEME_SCOPE, 1 );
327
- if (scheme) {
328
- if (!prevScheme) {
329
- this.themeSettingIdBeforeSchemeSwitch = this.settings.colorTheme;
330
- }
331
- return this.applyPreferredColorTheme(scheme);
332
- }
333
- else if (prevScheme && this.themeSettingIdBeforeSchemeSwitch) {
334
- const theme = this.colorThemeRegistry.findThemeBySettingsId(this.themeSettingIdBeforeSchemeSwitch, undefined);
335
- if (theme) {
336
- this.setColorTheme(theme.id, 'auto');
337
- }
338
- }
339
- }
340
- return undefined;
341
- }
342
- getPreferredColorScheme() {
343
- if (this.configurationService.getValue(ThemeSettings.DETECT_HC) && this.hostColorService.highContrast) {
344
- return this.hostColorService.dark ? ColorScheme.HIGH_CONTRAST_DARK : ColorScheme.HIGH_CONTRAST_LIGHT;
345
- }
346
- if (this.configurationService.getValue(ThemeSettings.DETECT_COLOR_SCHEME)) {
347
- return this.hostColorService.dark ? ColorScheme.DARK : ColorScheme.LIGHT;
348
- }
349
- return undefined;
350
- }
351
- async applyPreferredColorTheme(type) {
352
- let settingId;
353
- switch (type) {
354
- case ColorScheme.LIGHT:
355
- settingId = ThemeSettings.PREFERRED_LIGHT_THEME;
356
- break;
357
- case ColorScheme.HIGH_CONTRAST_DARK:
358
- settingId = ThemeSettings.PREFERRED_HC_DARK_THEME;
359
- break;
360
- case ColorScheme.HIGH_CONTRAST_LIGHT:
361
- settingId = ThemeSettings.PREFERRED_HC_LIGHT_THEME;
362
- break;
363
- default:
364
- settingId = ThemeSettings.PREFERRED_DARK_THEME;
365
- }
366
- const themeSettingId = this.configurationService.getValue(settingId);
367
- if (themeSettingId && typeof themeSettingId === 'string') {
368
- const theme = this.colorThemeRegistry.findThemeBySettingsId(themeSettingId, undefined);
369
- if (theme) {
370
- const configurationTarget = this.settings.findAutoConfigurationTarget(settingId);
371
- return this.setColorTheme(theme.id, configurationTarget);
372
- }
373
- }
374
- return null;
375
- }
376
- hasUpdatedDefaultThemes() {
377
- return this.hasDefaultUpdated;
378
- }
379
- getColorTheme() {
380
- return this.currentColorTheme;
381
- }
382
- async getColorThemes() {
383
- return this.colorThemeRegistry.getThemes();
384
- }
385
- async getMarketplaceColorThemes(publisher, name, version) {
386
- const extensionLocation = this.extensionResourceLoaderService.getExtensionGalleryResourceURL({ publisher, name, version }, 'extension');
387
- if (extensionLocation) {
388
- try {
389
- const manifestContent = await this.extensionResourceLoaderService.readExtensionResource(joinPath(extensionLocation, 'package.json'));
390
- return this.colorThemeRegistry.getMarketplaceThemes(JSON.parse(manifestContent), extensionLocation, ExtensionData.fromName(publisher, name));
391
- }
392
- catch (e) {
393
- this.logService.error('Problem loading themes from marketplace', e);
394
- }
395
- }
396
- return [];
397
- }
398
- get onDidColorThemeChange() {
399
- return this.onColorThemeChange.event;
400
- }
401
- setColorTheme(themeIdOrTheme, settingsTarget) {
402
- return this.colorThemeSequencer.queue(async () => {
403
- return this.internalSetColorTheme(themeIdOrTheme, settingsTarget);
404
- });
405
- }
406
- async internalSetColorTheme(themeIdOrTheme, settingsTarget) {
407
- if (!themeIdOrTheme) {
408
- return null;
409
- }
410
- const themeId = isString(themeIdOrTheme) ? validateThemeId(themeIdOrTheme) : themeIdOrTheme.id;
411
- if (this.currentColorTheme.isLoaded && themeId === this.currentColorTheme.id) {
412
- if (settingsTarget !== 'preview') {
413
- this.currentColorTheme.toStorage(this.storageService);
414
- }
415
- return this.settings.setColorTheme(this.currentColorTheme, settingsTarget);
416
- }
417
- let themeData = this.colorThemeRegistry.findThemeById(themeId);
418
- if (!themeData) {
419
- if (themeIdOrTheme instanceof ColorThemeData) {
420
- themeData = themeIdOrTheme;
421
- }
422
- else {
423
- return null;
424
- }
425
- }
426
- try {
427
- await themeData.ensureLoaded(this.extensionResourceLoaderService);
428
- themeData.setCustomizations(this.settings);
429
- return this.applyTheme(themeData, settingsTarget);
430
- }
431
- catch (error) {
432
- throw new Error(localizeWithPath('vs/workbench/services/themes/browser/workbenchThemeService', 'error.cannotloadtheme', "Unable to load {0}: {1}", themeData.location?.toString(), error.message));
433
- }
434
- }
435
- reloadCurrentColorTheme() {
436
- return this.colorThemeSequencer.queue(async () => {
437
- try {
438
- const theme = this.colorThemeRegistry.findThemeBySettingsId(this.currentColorTheme.settingsId) || this.currentColorTheme;
439
- await theme.reload(this.extensionResourceLoaderService);
440
- theme.setCustomizations(this.settings);
441
- await this.applyTheme(theme, undefined, false);
442
- }
443
- catch (error) {
444
- this.logService.info('Unable to reload {0}: {1}', this.currentColorTheme.location?.toString());
445
- }
446
- });
447
- }
448
- async restoreColorTheme() {
449
- return this.colorThemeSequencer.queue(async () => {
450
- const settingId = this.settings.colorTheme;
451
- const theme = this.colorThemeRegistry.findThemeBySettingsId(settingId);
452
- if (theme) {
453
- if (settingId !== this.currentColorTheme.settingsId) {
454
- await this.internalSetColorTheme(theme.id, undefined);
455
- }
456
- else if (theme !== this.currentColorTheme) {
457
- await theme.ensureLoaded(this.extensionResourceLoaderService);
458
- theme.setCustomizations(this.settings);
459
- await this.applyTheme(theme, undefined, true);
460
- }
461
- return true;
462
- }
463
- return false;
464
- });
465
- }
466
- updateDynamicCSSRules(themeData) {
467
- const cssRules = ( new Set());
468
- const ruleCollector = {
469
- addRule: (rule) => {
470
- if (!( cssRules.has(rule))) {
471
- cssRules.add(rule);
472
- }
473
- }
474
- };
475
- ruleCollector.addRule(`.monaco-workbench { forced-color-adjust: none; }`);
476
- themingRegistry.getThemingParticipants().forEach(p => p(themeData, ruleCollector, this.environmentService));
477
- const colorVariables = [];
478
- for (const item of getColorRegistry().getColors()) {
479
- const color = themeData.getColor(item.id, true);
480
- if (color) {
481
- colorVariables.push(`${asCssVariableName(item.id)}: ${( color.toString())};`);
482
- }
483
- }
484
- ruleCollector.addRule(`.monaco-workbench { ${colorVariables.join('\n')} }`);
485
- _applyRules([...cssRules].join('\n'), colorThemeRulesClassName);
486
- }
487
- applyTheme(newTheme, settingsTarget, silent = false) {
488
- this.updateDynamicCSSRules(newTheme);
489
- if (this.currentColorTheme.id) {
490
- this.container.classList.remove(...this.currentColorTheme.classNames);
491
- }
492
- else {
493
- this.container.classList.remove(VS_DARK_THEME, VS_LIGHT_THEME, VS_HC_THEME, VS_HC_LIGHT_THEME);
494
- }
495
- this.container.classList.add(...newTheme.classNames);
496
- this.currentColorTheme.clearCaches();
497
- this.currentColorTheme = newTheme;
498
- if (!this.colorThemingParticipantChangeListener) {
499
- this.colorThemingParticipantChangeListener = themingRegistry.onThemingParticipantAdded(_ => this.updateDynamicCSSRules(this.currentColorTheme));
500
- }
501
- this.colorThemeWatcher.update(newTheme);
502
- this.sendTelemetry(newTheme.id, newTheme.extensionData, 'color');
503
- if (silent) {
504
- return Promise.resolve(null);
505
- }
506
- this.onColorThemeChange.fire(this.currentColorTheme);
507
- if (newTheme.isLoaded && settingsTarget !== 'preview') {
508
- newTheme.toStorage(this.storageService);
509
- }
510
- return this.settings.setColorTheme(this.currentColorTheme, settingsTarget);
511
- }
512
- sendTelemetry(themeId, themeData, themeType) {
513
- if (themeData) {
514
- const key = themeType + themeData.extensionId;
515
- if (!this.themeExtensionsActivated.get(key)) {
516
- this.telemetryService.publicLog2('activatePlugin', {
517
- id: themeData.extensionId,
518
- name: themeData.extensionName,
519
- isBuiltin: themeData.extensionIsBuiltin,
520
- publisherDisplayName: themeData.extensionPublisher,
521
- themeId: themeId
522
- });
523
- this.themeExtensionsActivated.set(key, true);
524
- }
525
- }
526
- }
527
- async getFileIconThemes() {
528
- return this.fileIconThemeRegistry.getThemes();
529
- }
530
- getFileIconTheme() {
531
- return this.currentFileIconTheme;
532
- }
533
- get onDidFileIconThemeChange() {
534
- return this.onFileIconThemeChange.event;
535
- }
536
- async setFileIconTheme(iconThemeOrId, settingsTarget) {
537
- return this.fileIconThemeSequencer.queue(async () => {
538
- return this.internalSetFileIconTheme(iconThemeOrId, settingsTarget);
539
- });
540
- }
541
- async internalSetFileIconTheme(iconThemeOrId, settingsTarget) {
542
- if (iconThemeOrId === undefined) {
543
- iconThemeOrId = '';
544
- }
545
- const themeId = isString(iconThemeOrId) ? iconThemeOrId : iconThemeOrId.id;
546
- if (themeId !== this.currentFileIconTheme.id || !this.currentFileIconTheme.isLoaded) {
547
- let newThemeData = this.fileIconThemeRegistry.findThemeById(themeId);
548
- if (!newThemeData && iconThemeOrId instanceof FileIconThemeData) {
549
- newThemeData = iconThemeOrId;
550
- }
551
- if (!newThemeData) {
552
- newThemeData = FileIconThemeData.noIconTheme;
553
- }
554
- await newThemeData.ensureLoaded(this.fileIconThemeLoader);
555
- this.applyAndSetFileIconTheme(newThemeData);
556
- }
557
- const themeData = this.currentFileIconTheme;
558
- if (themeData.isLoaded && settingsTarget !== 'preview' && (!themeData.location || !getRemoteAuthority(themeData.location))) {
559
- themeData.toStorage(this.storageService);
560
- }
561
- await this.settings.setFileIconTheme(this.currentFileIconTheme, settingsTarget);
562
- return themeData;
563
- }
564
- async getMarketplaceFileIconThemes(publisher, name, version) {
565
- const extensionLocation = this.extensionResourceLoaderService.getExtensionGalleryResourceURL({ publisher, name, version }, 'extension');
566
- if (extensionLocation) {
567
- try {
568
- const manifestContent = await this.extensionResourceLoaderService.readExtensionResource(joinPath(extensionLocation, 'package.json'));
569
- return this.fileIconThemeRegistry.getMarketplaceThemes(JSON.parse(manifestContent), extensionLocation, ExtensionData.fromName(publisher, name));
570
- }
571
- catch (e) {
572
- this.logService.error('Problem loading themes from marketplace', e);
573
- }
574
- }
575
- return [];
576
- }
577
- async reloadCurrentFileIconTheme() {
578
- return this.fileIconThemeSequencer.queue(async () => {
579
- await this.currentFileIconTheme.reload(this.fileIconThemeLoader);
580
- this.applyAndSetFileIconTheme(this.currentFileIconTheme);
581
- });
582
- }
583
- async restoreFileIconTheme() {
584
- return this.fileIconThemeSequencer.queue(async () => {
585
- const settingId = this.settings.fileIconTheme;
586
- const theme = this.fileIconThemeRegistry.findThemeBySettingsId(settingId);
587
- if (theme) {
588
- if (settingId !== this.currentFileIconTheme.settingsId) {
589
- await this.internalSetFileIconTheme(theme.id, undefined);
590
- }
591
- else if (theme !== this.currentFileIconTheme) {
592
- await theme.ensureLoaded(this.fileIconThemeLoader);
593
- this.applyAndSetFileIconTheme(theme, true);
594
- }
595
- return true;
596
- }
597
- return false;
598
- });
599
- }
600
- applyAndSetFileIconTheme(iconThemeData, silent = false) {
601
- this.currentFileIconTheme = iconThemeData;
602
- _applyRules(iconThemeData.styleSheetContent, fileIconThemeRulesClassName);
603
- if (iconThemeData.id) {
604
- this.container.classList.add(fileIconsEnabledClass);
605
- }
606
- else {
607
- this.container.classList.remove(fileIconsEnabledClass);
608
- }
609
- this.fileIconThemeWatcher.update(iconThemeData);
610
- if (iconThemeData.id) {
611
- this.sendTelemetry(iconThemeData.id, iconThemeData.extensionData, 'fileIcon');
612
- }
613
- if (!silent) {
614
- this.onFileIconThemeChange.fire(this.currentFileIconTheme);
615
- }
616
- }
617
- async getProductIconThemes() {
618
- return this.productIconThemeRegistry.getThemes();
619
- }
620
- getProductIconTheme() {
621
- return this.currentProductIconTheme;
622
- }
623
- get onDidProductIconThemeChange() {
624
- return this.onProductIconThemeChange.event;
625
- }
626
- async setProductIconTheme(iconThemeOrId, settingsTarget) {
627
- return this.productIconThemeSequencer.queue(async () => {
628
- return this.internalSetProductIconTheme(iconThemeOrId, settingsTarget);
629
- });
630
- }
631
- async internalSetProductIconTheme(iconThemeOrId, settingsTarget) {
632
- if (iconThemeOrId === undefined) {
633
- iconThemeOrId = '';
634
- }
635
- const themeId = isString(iconThemeOrId) ? iconThemeOrId : iconThemeOrId.id;
636
- if (themeId !== this.currentProductIconTheme.id || !this.currentProductIconTheme.isLoaded) {
637
- let newThemeData = this.productIconThemeRegistry.findThemeById(themeId);
638
- if (!newThemeData && iconThemeOrId instanceof ProductIconThemeData) {
639
- newThemeData = iconThemeOrId;
640
- }
641
- if (!newThemeData) {
642
- newThemeData = ProductIconThemeData.defaultTheme;
643
- }
644
- await newThemeData.ensureLoaded(this.extensionResourceLoaderService, this.logService);
645
- this.applyAndSetProductIconTheme(newThemeData);
646
- }
647
- const themeData = this.currentProductIconTheme;
648
- if (themeData.isLoaded && settingsTarget !== 'preview' && (!themeData.location || !getRemoteAuthority(themeData.location))) {
649
- themeData.toStorage(this.storageService);
650
- }
651
- await this.settings.setProductIconTheme(this.currentProductIconTheme, settingsTarget);
652
- return themeData;
653
- }
654
- async getMarketplaceProductIconThemes(publisher, name, version) {
655
- const extensionLocation = this.extensionResourceLoaderService.getExtensionGalleryResourceURL({ publisher, name, version }, 'extension');
656
- if (extensionLocation) {
657
- try {
658
- const manifestContent = await this.extensionResourceLoaderService.readExtensionResource(joinPath(extensionLocation, 'package.json'));
659
- return this.productIconThemeRegistry.getMarketplaceThemes(JSON.parse(manifestContent), extensionLocation, ExtensionData.fromName(publisher, name));
660
- }
661
- catch (e) {
662
- this.logService.error('Problem loading themes from marketplace', e);
663
- }
664
- }
665
- return [];
666
- }
667
- async reloadCurrentProductIconTheme() {
668
- return this.productIconThemeSequencer.queue(async () => {
669
- await this.currentProductIconTheme.reload(this.extensionResourceLoaderService, this.logService);
670
- this.applyAndSetProductIconTheme(this.currentProductIconTheme);
671
- });
672
- }
673
- async restoreProductIconTheme() {
674
- return this.productIconThemeSequencer.queue(async () => {
675
- const settingId = this.settings.productIconTheme;
676
- const theme = this.productIconThemeRegistry.findThemeBySettingsId(settingId);
677
- if (theme) {
678
- if (settingId !== this.currentProductIconTheme.settingsId) {
679
- await this.internalSetProductIconTheme(theme.id, undefined);
680
- }
681
- else if (theme !== this.currentProductIconTheme) {
682
- await theme.ensureLoaded(this.extensionResourceLoaderService, this.logService);
683
- this.applyAndSetProductIconTheme(theme, true);
684
- }
685
- return true;
686
- }
687
- return false;
688
- });
689
- }
690
- applyAndSetProductIconTheme(iconThemeData, silent = false) {
691
- this.currentProductIconTheme = iconThemeData;
692
- _applyRules(iconThemeData.styleSheetContent, productIconThemeRulesClassName);
693
- this.productIconThemeWatcher.update(iconThemeData);
694
- if (iconThemeData.id) {
695
- this.sendTelemetry(iconThemeData.id, iconThemeData.extensionData, 'productIcon');
696
- }
697
- if (!silent) {
698
- this.onProductIconThemeChange.fire(this.currentProductIconTheme);
699
- }
700
- }
701
- };
702
- WorkbenchThemeService = ( __decorate([
703
- ( __param(0, IExtensionService)),
704
- ( __param(1, IStorageService)),
705
- ( __param(2, IConfigurationService)),
706
- ( __param(3, ITelemetryService)),
707
- ( __param(4, IBrowserWorkbenchEnvironmentService)),
708
- ( __param(5, IFileService)),
709
- ( __param(6, IExtensionResourceLoaderService)),
710
- ( __param(7, IWorkbenchLayoutService)),
711
- ( __param(8, ILogService)),
712
- ( __param(9, IHostColorSchemeService)),
713
- ( __param(10, IUserDataInitializationService)),
714
- ( __param(11, ILanguageService))
715
- ], WorkbenchThemeService));
716
- class ThemeFileWatcher {
717
- constructor(fileService, environmentService, onUpdate) {
718
- this.fileService = fileService;
719
- this.environmentService = environmentService;
720
- this.onUpdate = onUpdate;
721
- }
722
- update(theme) {
723
- if (!isEqual(theme.location, this.watchedLocation)) {
724
- this.dispose();
725
- if (theme.location && (theme.watch || this.environmentService.isExtensionDevelopment)) {
726
- this.watchedLocation = theme.location;
727
- this.watcherDisposable = this.fileService.watch(theme.location);
728
- this.fileService.onDidFilesChange(e => {
729
- if (this.watchedLocation && e.contains(this.watchedLocation, 0 )) {
730
- this.onUpdate();
731
- }
732
- });
733
- }
734
- }
735
- }
736
- dispose() {
737
- this.watcherDisposable = dispose(this.watcherDisposable);
738
- this.fileChangeListener = dispose(this.fileChangeListener);
739
- this.watchedLocation = undefined;
740
- }
741
- }
742
- function _applyRules(styleSheetContent, rulesClassName) {
743
- const themeStyles = mainWindow.document.head.getElementsByClassName(rulesClassName);
744
- if (themeStyles.length === 0) {
745
- const elStyle = createStyleSheet();
746
- elStyle.className = rulesClassName;
747
- elStyle.textContent = styleSheetContent;
748
- }
749
- else {
750
- themeStyles[0].textContent = styleSheetContent;
751
- }
752
- }
753
- registerColorThemeSchemas();
754
- registerFileIconThemeSchemas();
755
- registerProductIconThemeSchemas();
756
-
757
- export { WorkbenchThemeService };