-
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 (#6913)
* better handling loading terminal fonts timing issues, fix #5019 Signed-off-by: Roman <ixrock@gmail.com> * refactoring, loading all terminal fonts to earliest stage app starting Signed-off-by: Roman <ixrock@gmail.com> * attempt to fix tests Signed-off-by: Roman <ixrock@gmail.com> Signed-off-by: Roman <ixrock@gmail.com>
- Loading branch information
Showing
8 changed files
with
116 additions
and
105 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
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
14 changes: 14 additions & 0 deletions
14
src/renderer/components/dock/terminal/terminal-fonts.global-override-for-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,14 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override"; | ||
import { preloadAllTerminalFontsInjectable } from "./terminal-fonts.injectable"; | ||
|
||
export default getGlobalOverride(preloadAllTerminalFontsInjectable, () => { | ||
return { | ||
id: "", | ||
async run() { | ||
}, | ||
}; | ||
}); |
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
/** | ||
* 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 { beforeFrameStartsFirstInjectionToken } from "../../../before-frame-starts/tokens"; | ||
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 { | ||
id: "preload-all-terminal-fonts", | ||
|
||
async run() { | ||
await Promise.allSettled( | ||
Array.from(terminalFonts.keys()).map(preloadFont), | ||
); | ||
}, | ||
}; | ||
}, | ||
|
||
injectionToken: beforeFrameStartsFirstInjectionToken, | ||
|
||
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