Skip to content

Commit 39fdb27

Browse files
authored
[themes] When opening a new window, product icons don't load immediately (microsoft#155485)
[themes] When opening a new window, product icons don't load immediatel. Fixes microsoft#142236
1 parent ebe7a4e commit 39fdb27

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/vs/platform/theme/common/iconRegistry.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
77
import { Codicon, CSSIcon } from 'vs/base/common/codicons';
88
import { Emitter, Event } from 'vs/base/common/event';
99
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
10+
import { isString } from 'vs/base/common/types';
1011
import { URI } from 'vs/base/common/uri';
1112
import { localize } from 'vs/nls';
1213
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
@@ -62,6 +63,28 @@ export interface IconFontDefinition {
6263
readonly src: IconFontSource[];
6364
}
6465

66+
export namespace IconFontDefinition {
67+
export function toJSONObject(iconFont: IconFontDefinition): any {
68+
return {
69+
weight: iconFont.weight,
70+
style: iconFont.style,
71+
src: iconFont.src.map(s => ({ format: s.format, location: s.location.toString() }))
72+
};
73+
}
74+
export function fromJSONObject(json: any): IconFontDefinition | undefined {
75+
const stringOrUndef = (s: any) => isString(s) ? s : undefined;
76+
if (json && Array.isArray(json.src) && json.src.every((s: any) => isString(s.format) && isString(s.location))) {
77+
return {
78+
weight: stringOrUndef(json.weight),
79+
style: stringOrUndef(json.style),
80+
src: json.src.map((s: any) => ({ format: s.format, location: URI.parse(s.location) }))
81+
};
82+
}
83+
return undefined;
84+
}
85+
}
86+
87+
6588
export interface IconFontSource {
6689
readonly location: URI;
6790
readonly format: string;

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
1313
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
1414
import { DEFAULT_PRODUCT_ICON_THEME_SETTING_VALUE } from 'vs/workbench/services/themes/common/themeConfiguration';
1515
import { fontIdRegex, fontWeightRegex, fontStyleRegex, fontFormatRegex } from 'vs/workbench/services/themes/common/productIconThemeSchema';
16-
import { isString } from 'vs/base/common/types';
16+
import { isObject, isString } from 'vs/base/common/types';
1717
import { ILogService } from 'vs/platform/log/common/log';
1818
import { IconDefinition, getIconRegistry, IconContribution, IconFontDefinition, IconFontSource } from 'vs/platform/theme/common/iconRegistry';
1919
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
@@ -132,13 +132,40 @@ export class ProductIconThemeData implements IWorkbenchProductIconTheme {
132132
break;
133133
}
134134
}
135+
const { iconDefinitions, iconFontDefinitions } = data;
136+
if (Array.isArray(iconDefinitions) && isObject(iconFontDefinitions)) {
137+
const restoredIconDefinitions = new Map<string, IconDefinition>();
138+
for (const entry of iconDefinitions) {
139+
const { id, fontCharacter, fontId } = entry;
140+
if (isString(id) && isString(fontCharacter)) {
141+
if (isString(fontId)) {
142+
const iconFontDefinition = IconFontDefinition.fromJSONObject(iconFontDefinitions[fontId]);
143+
if (iconFontDefinition) {
144+
restoredIconDefinitions.set(id, { fontCharacter, font: { id: fontId, definition: iconFontDefinition } });
145+
}
146+
} else {
147+
restoredIconDefinitions.set(id, { fontCharacter });
148+
}
149+
}
150+
}
151+
theme.iconThemeDocument = { iconDefinitions: restoredIconDefinitions };
152+
}
135153
return theme;
136154
} catch (e) {
137155
return undefined;
138156
}
139157
}
140158

141159
toStorage(storageService: IStorageService) {
160+
const iconDefinitions = [];
161+
const iconFontDefinitions: { [id: string]: IconFontDefinition } = {};
162+
for (const entry of this.iconThemeDocument.iconDefinitions.entries()) {
163+
const font = entry[1].font;
164+
iconDefinitions.push({ id: entry[0], fontCharacter: entry[1].fontCharacter, fontId: font?.id });
165+
if (font && iconFontDefinitions[font.id] === undefined) {
166+
iconFontDefinitions[font.id] = IconFontDefinition.toJSONObject(font.definition);
167+
}
168+
}
142169
const data = JSON.stringify({
143170
id: this.id,
144171
label: this.label,
@@ -147,6 +174,8 @@ export class ProductIconThemeData implements IWorkbenchProductIconTheme {
147174
styleSheetContent: this.styleSheetContent,
148175
watch: this.watch,
149176
extensionData: ExtensionData.toJSONObject(this.extensionData),
177+
iconDefinitions,
178+
iconFontDefinitions
150179
});
151180
storageService.store(ProductIconThemeData.STORAGE_KEY, data, StorageScope.PROFILE, StorageTarget.MACHINE);
152181
}

0 commit comments

Comments
 (0)