-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better handling loading terminal fonts timing issues, fix #5019
Signed-off-by: Roman <ixrock@gmail.com>
- Loading branch information
Showing
8 changed files
with
106 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/renderer/components/dock/terminal/terminal-fonts.injectable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import RobotoMono from "../../../fonts/Roboto-Mono-nerd.ttf"; // patched font with icons | ||
import AnonymousPro from "../../../fonts/AnonymousPro-Regular.ttf"; | ||
import IBMPlexMono from "../../../fonts/IBMPlexMono-Regular.ttf"; | ||
import JetBrainsMono from "../../../fonts/JetBrainsMono-Regular.ttf"; | ||
import RedHatMono from "../../../fonts/RedHatMono-Regular.ttf"; | ||
import SourceCodePro from "../../../fonts/SourceCodePro-Regular.ttf"; | ||
import SpaceMono from "../../../fonts/SpaceMono-Regular.ttf"; | ||
import UbuntuMono from "../../../fonts/UbuntuMono-Regular.ttf"; | ||
|
||
export const terminalFontsInjectable = getInjectable({ | ||
id: "terminalFontsInjectable", | ||
|
||
instantiate() { | ||
return new Map([ | ||
["RobotoMono", RobotoMono], | ||
["Anonymous Pro", AnonymousPro], | ||
["IBM Plex Mono", IBMPlexMono], | ||
["JetBrains Mono", JetBrainsMono], | ||
["Red Hat Mono", RedHatMono], | ||
["Source Code Pro", SourceCodePro], | ||
["Space Mono", SpaceMono], | ||
["Ubuntu Mono", UbuntuMono], | ||
]); | ||
}, | ||
}); | ||
|
||
|
||
export const preloadTerminalFontInjectable = getInjectable({ | ||
id: "preloadTerminalFontInjectable", | ||
|
||
instantiate(di) { | ||
const terminalFonts = di.inject(terminalFontsInjectable); | ||
|
||
return async function (fontFamily: string): Promise<void> { | ||
const fontBundledPath = terminalFonts.get(fontFamily); | ||
const fontLoaded = document.fonts.check(`10px ${fontFamily}`); | ||
|
||
if (fontLoaded || !fontBundledPath) return; | ||
|
||
const font = new FontFace(fontFamily, `url(${fontBundledPath})`); | ||
|
||
document.fonts.add(font); | ||
await font.load(); | ||
}; | ||
}, | ||
|
||
causesSideEffects: true, | ||
}); | ||
|
||
export const preloadAllTerminalFontsInjectable = getInjectable({ | ||
id: "preloadAllTerminalFontsInjectable", | ||
|
||
instantiate(di) { | ||
const terminalFonts = di.inject(terminalFontsInjectable); | ||
const preloadFont = di.inject(preloadTerminalFontInjectable); | ||
|
||
return async function (): Promise<any> { | ||
return Promise.allSettled( | ||
Array.from(terminalFonts.keys()).map(preloadFont), | ||
); | ||
}; | ||
}, | ||
|
||
causesSideEffects: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters