Skip to content

Commit 9057a71

Browse files
committed
Overriding color theme is not picked when changed. Fixes microsoft#138160
1 parent aed641a commit 9057a71

File tree

1 file changed

+85
-71
lines changed

1 file changed

+85
-71
lines changed

src/vs/workbench/services/themes/browser/workbenchThemeService.ts

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -426,33 +426,38 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
426426

427427
public setColorTheme(themeIdOrTheme: string | undefined | IWorkbenchColorTheme, settingsTarget: ThemeSettingTarget): Promise<IWorkbenchColorTheme | null> {
428428
return this.colorThemeSequencer.queue(async () => {
429-
if (!themeIdOrTheme) {
430-
return null;
431-
}
432-
const themeId = types.isString(themeIdOrTheme) ? validateThemeId(themeIdOrTheme) : themeIdOrTheme.id;
433-
if (this.currentColorTheme.isLoaded && themeId === this.currentColorTheme.id) {
434-
if (settingsTarget !== 'preview') {
435-
this.currentColorTheme.toStorage(this.storageService);
436-
}
437-
return this.settings.setColorTheme(this.currentColorTheme, settingsTarget);
438-
}
429+
return this.internalSetColorTheme(themeIdOrTheme, settingsTarget);
430+
});
431+
}
439432

440-
let themeData = this.colorThemeRegistry.findThemeById(themeId);
441-
if (!themeData) {
442-
if (themeIdOrTheme instanceof ColorThemeData) {
443-
themeData = themeIdOrTheme;
444-
} else {
445-
return null;
446-
}
433+
private async internalSetColorTheme(themeIdOrTheme: string | undefined | IWorkbenchColorTheme, settingsTarget: ThemeSettingTarget): Promise<IWorkbenchColorTheme | null> {
434+
if (!themeIdOrTheme) {
435+
return null;
436+
}
437+
const themeId = types.isString(themeIdOrTheme) ? validateThemeId(themeIdOrTheme) : themeIdOrTheme.id;
438+
if (this.currentColorTheme.isLoaded && themeId === this.currentColorTheme.id) {
439+
if (settingsTarget !== 'preview') {
440+
this.currentColorTheme.toStorage(this.storageService);
447441
}
448-
try {
449-
await themeData.ensureLoaded(this.extensionResourceLoaderService);
450-
themeData.setCustomizations(this.settings);
451-
return this.applyTheme(themeData, settingsTarget);
452-
} catch (error) {
453-
throw new Error(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.location?.toString(), error.message));
442+
return this.settings.setColorTheme(this.currentColorTheme, settingsTarget);
443+
}
444+
445+
let themeData = this.colorThemeRegistry.findThemeById(themeId);
446+
if (!themeData) {
447+
if (themeIdOrTheme instanceof ColorThemeData) {
448+
themeData = themeIdOrTheme;
449+
} else {
450+
return null;
454451
}
455-
});
452+
}
453+
try {
454+
await themeData.ensureLoaded(this.extensionResourceLoaderService);
455+
themeData.setCustomizations(this.settings);
456+
return this.applyTheme(themeData, settingsTarget);
457+
} catch (error) {
458+
throw new Error(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.location?.toString(), error.message));
459+
}
460+
456461
}
457462

458463
private reloadCurrentColorTheme() {
@@ -474,7 +479,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
474479
const theme = this.colorThemeRegistry.findThemeBySettingsId(settingId);
475480
if (theme) {
476481
if (settingId !== this.currentColorTheme.settingsId) {
477-
await this.setColorTheme(theme.id, undefined);
482+
await this.internalSetColorTheme(theme.id, undefined);
478483
} else if (theme !== this.currentColorTheme) {
479484
theme.setCustomizations(this.settings);
480485
await this.applyTheme(theme, undefined, true);
@@ -589,34 +594,38 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
589594

590595
public async setFileIconTheme(iconThemeOrId: string | undefined | IWorkbenchFileIconTheme, settingsTarget: ThemeSettingTarget): Promise<IWorkbenchFileIconTheme> {
591596
return this.fileIconThemeSequencer.queue(async () => {
592-
if (iconThemeOrId === undefined) {
593-
iconThemeOrId = '';
594-
}
595-
const themeId = types.isString(iconThemeOrId) ? iconThemeOrId : iconThemeOrId.id;
596-
if (themeId !== this.currentFileIconTheme.id || !this.currentFileIconTheme.isLoaded) {
597+
return this.internalSetFileIconTheme(iconThemeOrId, settingsTarget);
598+
});
599+
}
597600

598-
let newThemeData = this.fileIconThemeRegistry.findThemeById(themeId);
599-
if (!newThemeData && iconThemeOrId instanceof FileIconThemeData) {
600-
newThemeData = iconThemeOrId;
601-
}
602-
if (!newThemeData) {
603-
newThemeData = FileIconThemeData.noIconTheme;
604-
}
605-
await newThemeData.ensureLoaded(this.extensionResourceLoaderService);
601+
private async internalSetFileIconTheme(iconThemeOrId: string | undefined | IWorkbenchFileIconTheme, settingsTarget: ThemeSettingTarget): Promise<IWorkbenchFileIconTheme> {
602+
if (iconThemeOrId === undefined) {
603+
iconThemeOrId = '';
604+
}
605+
const themeId = types.isString(iconThemeOrId) ? iconThemeOrId : iconThemeOrId.id;
606+
if (themeId !== this.currentFileIconTheme.id || !this.currentFileIconTheme.isLoaded) {
606607

607-
this.applyAndSetFileIconTheme(newThemeData); // updates this.currentFileIconTheme
608+
let newThemeData = this.fileIconThemeRegistry.findThemeById(themeId);
609+
if (!newThemeData && iconThemeOrId instanceof FileIconThemeData) {
610+
newThemeData = iconThemeOrId;
611+
}
612+
if (!newThemeData) {
613+
newThemeData = FileIconThemeData.noIconTheme;
608614
}
615+
await newThemeData.ensureLoaded(this.extensionResourceLoaderService);
609616

610-
const themeData = this.currentFileIconTheme;
617+
this.applyAndSetFileIconTheme(newThemeData); // updates this.currentFileIconTheme
618+
}
611619

612-
// remember theme data for a quick restore
613-
if (themeData.isLoaded && settingsTarget !== 'preview' && (!themeData.location || !getRemoteAuthority(themeData.location))) {
614-
themeData.toStorage(this.storageService);
615-
}
616-
await this.settings.setFileIconTheme(this.currentFileIconTheme, settingsTarget);
620+
const themeData = this.currentFileIconTheme;
617621

618-
return themeData;
619-
});
622+
// remember theme data for a quick restore
623+
if (themeData.isLoaded && settingsTarget !== 'preview' && (!themeData.location || !getRemoteAuthority(themeData.location))) {
624+
themeData.toStorage(this.storageService);
625+
}
626+
await this.settings.setFileIconTheme(this.currentFileIconTheme, settingsTarget);
627+
628+
return themeData;
620629
}
621630

622631
public async getMarketplaceFileIconThemes(publisher: string, name: string, version: string): Promise<IWorkbenchFileIconTheme[]> {
@@ -645,7 +654,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
645654
const theme = this.fileIconThemeRegistry.findThemeBySettingsId(settingId);
646655
if (theme) {
647656
if (settingId !== this.currentFileIconTheme.settingsId) {
648-
await this.setFileIconTheme(theme.id, undefined);
657+
await this.internalSetFileIconTheme(theme.id, undefined);
649658
} else if (theme !== this.currentFileIconTheme) {
650659
this.applyAndSetFileIconTheme(theme, true);
651660
}
@@ -691,32 +700,37 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
691700

692701
public async setProductIconTheme(iconThemeOrId: string | undefined | IWorkbenchProductIconTheme, settingsTarget: ThemeSettingTarget): Promise<IWorkbenchProductIconTheme> {
693702
return this.productIconThemeSequencer.queue(async () => {
694-
if (iconThemeOrId === undefined) {
695-
iconThemeOrId = '';
696-
}
697-
const themeId = types.isString(iconThemeOrId) ? iconThemeOrId : iconThemeOrId.id;
698-
if (themeId !== this.currentProductIconTheme.id || !this.currentProductIconTheme.isLoaded) {
699-
let newThemeData = this.productIconThemeRegistry.findThemeById(themeId);
700-
if (!newThemeData && iconThemeOrId instanceof ProductIconThemeData) {
701-
newThemeData = iconThemeOrId;
702-
}
703-
if (!newThemeData) {
704-
newThemeData = ProductIconThemeData.defaultTheme;
705-
}
706-
await newThemeData.ensureLoaded(this.extensionResourceLoaderService, this.logService);
703+
return this.internalSetProductIconTheme(iconThemeOrId, settingsTarget);
704+
});
705+
}
707706

708-
this.applyAndSetProductIconTheme(newThemeData); // updates this.currentProductIconTheme
707+
private async internalSetProductIconTheme(iconThemeOrId: string | undefined | IWorkbenchProductIconTheme, settingsTarget: ThemeSettingTarget): Promise<IWorkbenchProductIconTheme> {
708+
if (iconThemeOrId === undefined) {
709+
iconThemeOrId = '';
710+
}
711+
const themeId = types.isString(iconThemeOrId) ? iconThemeOrId : iconThemeOrId.id;
712+
if (themeId !== this.currentProductIconTheme.id || !this.currentProductIconTheme.isLoaded) {
713+
let newThemeData = this.productIconThemeRegistry.findThemeById(themeId);
714+
if (!newThemeData && iconThemeOrId instanceof ProductIconThemeData) {
715+
newThemeData = iconThemeOrId;
709716
}
710-
const themeData = this.currentProductIconTheme;
711-
712-
// remember theme data for a quick restore
713-
if (themeData.isLoaded && settingsTarget !== 'preview' && (!themeData.location || !getRemoteAuthority(themeData.location))) {
714-
themeData.toStorage(this.storageService);
717+
if (!newThemeData) {
718+
newThemeData = ProductIconThemeData.defaultTheme;
715719
}
716-
await this.settings.setProductIconTheme(this.currentProductIconTheme, settingsTarget);
720+
await newThemeData.ensureLoaded(this.extensionResourceLoaderService, this.logService);
721+
722+
this.applyAndSetProductIconTheme(newThemeData); // updates this.currentProductIconTheme
723+
}
724+
const themeData = this.currentProductIconTheme;
725+
726+
// remember theme data for a quick restore
727+
if (themeData.isLoaded && settingsTarget !== 'preview' && (!themeData.location || !getRemoteAuthority(themeData.location))) {
728+
themeData.toStorage(this.storageService);
729+
}
730+
await this.settings.setProductIconTheme(this.currentProductIconTheme, settingsTarget);
731+
732+
return themeData;
717733

718-
return themeData;
719-
});
720734
}
721735

722736
public async getMarketplaceProductIconThemes(publisher: string, name: string, version: string): Promise<IWorkbenchProductIconTheme[]> {
@@ -745,7 +759,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
745759
const theme = this.productIconThemeRegistry.findThemeBySettingsId(settingId);
746760
if (theme) {
747761
if (settingId !== this.currentProductIconTheme.settingsId) {
748-
await this.setProductIconTheme(theme.id, undefined);
762+
await this.internalSetProductIconTheme(theme.id, undefined);
749763
} else if (theme !== this.currentProductIconTheme) {
750764
this.applyAndSetProductIconTheme(theme, true);
751765
}

0 commit comments

Comments
 (0)