Skip to content

Commit

Permalink
generate whole browser url from server side
Browse files Browse the repository at this point in the history
Signed-off-by: lstocchi <lstocchi@redhat.com>
  • Loading branch information
lstocchi committed Jul 5, 2023
1 parent 56c29ce commit 366dfed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/main/src/plugin/icon-registry.spec.ts
Expand Up @@ -81,7 +81,7 @@ test('should register icon contribution', async () => {
{
format: 'woff2',
location: `${extensionPath}/${fontPath}`,
browserURL: `${extensionPath}/${fontPath}`,
browserURL: `url('file://${extensionPath}/${fontPath}')`,
},
]);
expect(icon.definition.font?.fontId).toBe(`${extensionId}-${fontPath}`);
Expand Down
5 changes: 3 additions & 2 deletions packages/main/src/plugin/icon-registry.ts
Expand Up @@ -96,10 +96,11 @@ export class IconRegistry {
// fontId is based on the extension id and the font path
const fontId = `${extension.id}-${defaultAttributes.fontPath}`;

let browserURL = iconFontLocation;
let cleanedIconFontLocation = iconFontLocation.replace(/'/g, '%27');
if (isWindows()) {
browserURL = browserURL.replace(/\\/g, '/');
cleanedIconFontLocation = cleanedIconFontLocation.replace(/\\/g, '/');
}
const browserURL = `url('file://${cleanedIconFontLocation}')`;

// font definition
const fontDefinition: FontDefinition = {
Expand Down
6 changes: 1 addition & 5 deletions packages/renderer/src/lib/style/IconsStyle.svelte
Expand Up @@ -18,10 +18,6 @@ function createStyleSheet(): HTMLStyleElement {
return style;
}
export function toUrl(location: string) {
return `url('file://${location.replace(/'/g, '%27')}')`;
}
onMount(() => {
createStyleSheet();
Expand All @@ -46,7 +42,7 @@ onMount(() => {
});
fontsToAdd.forEach(font => {
const src = font.src.map(l => `${toUrl(l.browserURL)} format('${l.format}')`).join(', ');
const src = font.src.map(l => `${l.browserURL} format('${l.format}')`).join(', ');
styles.push(
`@font-face { src: ${src}; font-family: '${font.fontId.replace(/'/g, '%27')}'; font-display: block; }`,
);
Expand Down

0 comments on commit 366dfed

Please sign in to comment.