mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup loading terminal fonts (#6937)
* Cleanup loading terminal fonts - Make list of possible fonts fully OCP - Only mark the loading of a font as 'causesSideEffects' - Make a view model for the terminal font preferences component - Move the TTF files next to where they are registered to help with finding them Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup formatting and change model to presenter Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
cf27605a21
commit
e635d82ea5
25 files changed
+298
-140
No files matched your search
-14
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* 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() {
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
/**
|
||||
* 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,
|
||||
});
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user