From e635d82ea5f955ce4c8f4ccffaf77f0e6c1c7440 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 17 Jan 2023 05:11:52 -0800 Subject: [PATCH 1/2] 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 * Fix tests Signed-off-by: Sebastian Malton * Cleanup formatting and change model to presenter Signed-off-by: Sebastian Malton Signed-off-by: Sebastian Malton --- .../terminal-font-family.tsx | 68 ++++----------- .../terminal-font-options.injectable.tsx | 50 +++++++++++ .../renderer/fonts/AnonymousPro-Regular.ttf | Bin .../renderer/fonts/IBMPlexMono-Regular.ttf | Bin .../renderer/fonts/JetBrainsMono-Regular.ttf | Bin .../renderer/fonts/RedHatMono-Regular.ttf | Bin .../terminal/renderer/fonts/Roboto-Mono.ttf} | Bin .../renderer/fonts/SourceCodePro-Regular.ttf | Bin .../renderer/fonts/SpaceMono-Regular.ttf | Bin .../renderer/fonts/UbuntuMono-Regular.ttf | Bin .../fonts/anonymous-pro.injectable.ts | 18 ++++ .../renderer/fonts/fonts.injectable.ts | 13 +++ .../fonts/ibm-plex-mono.injectable.ts | 18 ++++ .../fonts/jetbrains-mono.injectable.ts | 18 ++++ ...ad-font.global-override-for-injectable.ts} | 11 +-- .../renderer/fonts/load-font.injectable.ts | 27 ++++++ .../fonts/preload-fonts.injectable.ts | 24 ++++++ .../renderer/fonts/red-hat-mono.injectable.ts | 18 ++++ .../renderer/fonts/roboto-mono.injectable.ts | 18 ++++ .../fonts/source-code-pro.injectable.ts | 18 ++++ .../renderer/fonts/space-mono.injectable.ts | 18 ++++ src/features/terminal/renderer/fonts/token.ts | 15 ++++ .../renderer/fonts/ubuntu-mono.injectable.ts | 18 ++++ .../terminal/terminal-fonts.injectable.ts | 78 ------------------ types/mocks.d.ts | 6 +- 25 files changed, 297 insertions(+), 139 deletions(-) create mode 100644 src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-options.injectable.tsx rename src/{ => features/terminal}/renderer/fonts/AnonymousPro-Regular.ttf (100%) rename src/{ => features/terminal}/renderer/fonts/IBMPlexMono-Regular.ttf (100%) rename src/{ => features/terminal}/renderer/fonts/JetBrainsMono-Regular.ttf (100%) rename src/{ => features/terminal}/renderer/fonts/RedHatMono-Regular.ttf (100%) rename src/{renderer/fonts/Roboto-Mono-nerd.ttf => features/terminal/renderer/fonts/Roboto-Mono.ttf} (100%) rename src/{ => features/terminal}/renderer/fonts/SourceCodePro-Regular.ttf (100%) rename src/{ => features/terminal}/renderer/fonts/SpaceMono-Regular.ttf (100%) rename src/{ => features/terminal}/renderer/fonts/UbuntuMono-Regular.ttf (100%) create mode 100644 src/features/terminal/renderer/fonts/anonymous-pro.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/fonts.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/ibm-plex-mono.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/jetbrains-mono.injectable.ts rename src/{renderer/components/dock/terminal/terminal-fonts.global-override-for-injectable.ts => features/terminal/renderer/fonts/load-font.global-override-for-injectable.ts} (52%) create mode 100644 src/features/terminal/renderer/fonts/load-font.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/preload-fonts.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/red-hat-mono.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/roboto-mono.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/source-code-pro.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/space-mono.injectable.ts create mode 100644 src/features/terminal/renderer/fonts/token.ts create mode 100644 src/features/terminal/renderer/fonts/ubuntu-mono.injectable.ts delete mode 100644 src/renderer/components/dock/terminal/terminal-fonts.injectable.ts diff --git a/src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-family.tsx b/src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-family.tsx index 7ff161862ec6..cdd7a966337b 100644 --- a/src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-family.tsx +++ b/src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-family.tsx @@ -5,66 +5,30 @@ import React from "react"; import { SubTitle } from "../../../../../../renderer/components/layout/sub-title"; import { withInjectables } from "@ogre-tools/injectable-react"; -import type { UserStore } from "../../../../../../common/user-store"; -import userStoreInjectable from "../../../../../../common/user-store/user-store.injectable"; import { observer } from "mobx-react"; -import type { SelectOption } from "../../../../../../renderer/components/select"; import { Select } from "../../../../../../renderer/components/select"; -import type { Logger } from "../../../../../../common/logger"; -import { action } from "mobx"; -import loggerInjectable from "../../../../../../common/logger.injectable"; -import { - terminalFontsInjectable, -} from "../../../../../../renderer/components/dock/terminal/terminal-fonts.injectable"; +import type { TerminalFontPreferencePresenter } from "./terminal-font-options.injectable"; +import terminalFontPreferencePresenterInjectable from "./terminal-font-options.injectable"; interface Dependencies { - userStore: UserStore; - logger: Logger; - terminalFonts: Map; + model: TerminalFontPreferencePresenter; } -const NonInjectedTerminalFontFamily = observer( - ({ userStore, logger, terminalFonts }: Dependencies) => { - const bundledFonts: SelectOption[] = Array.from(terminalFonts.keys()).map(font => { - const { fontFamily, fontSize } = userStore.terminalConfig; - - return { - label: ( - - {font} - - ), - value: font, - isSelected: fontFamily === font, - }; - }); - - const onFontFamilyChange = action(({ value: fontFamily }: SelectOption) => { - logger.info(`setting terminal font to ${fontFamily}`); - - userStore.terminalConfig.fontFamily = fontFamily; // save to external storage - }); - - - return ( -
- - +
+)); export const TerminalFontFamily = withInjectables(NonInjectedTerminalFontFamily, { getProps: (di) => ({ - userStore: di.inject(userStoreInjectable), - logger: di.inject(loggerInjectable), - terminalFonts: di.inject(terminalFontsInjectable), + model: di.inject(terminalFontPreferencePresenterInjectable), }), }); diff --git a/src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-options.injectable.tsx b/src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-options.injectable.tsx new file mode 100644 index 000000000000..3d6a0d2ae06c --- /dev/null +++ b/src/features/preferences/renderer/preference-items/terminal/terminal-font-family/terminal-font-options.injectable.tsx @@ -0,0 +1,50 @@ +/** + * 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 type { IComputedValue } from "mobx"; +import { action, computed } from "mobx"; +import React from "react"; +import type { SingleValue } from "react-select"; +import userStoreInjectable from "../../../../../../common/user-store/user-store.injectable"; +import { defaultTerminalFontFamily } from "../../../../../../common/vars"; +import type { SelectOption } from "../../../../../../renderer/components/select"; +import { terminalFontInjectionToken } from "../../../../../terminal/renderer/fonts/token"; + +export interface TerminalFontPreferencePresenter { + readonly options: IComputedValue[]>; + readonly current: IComputedValue; + onSelection: (selection: SingleValue>) => void; +} + +const terminalFontPreferencePresenterInjectable = getInjectable({ + id: "terminal-font-preference-presenter", + instantiate: (di): TerminalFontPreferencePresenter => { + const userStore = di.inject(userStoreInjectable); + const terminalFonts = di.injectMany(terminalFontInjectionToken); + + return { + options: computed(() => terminalFonts.map(font => ({ + label: ( + + {font.name} + + ), + value: font.name, + isSelected: userStore.terminalConfig.fontFamily === font.name, + }))), + current: computed(() => userStore.terminalConfig.fontFamily), + onSelection: action(selection => { + userStore.terminalConfig.fontFamily = selection?.value ?? defaultTerminalFontFamily; + }), + }; + }, +}); + +export default terminalFontPreferencePresenterInjectable; diff --git a/src/renderer/fonts/AnonymousPro-Regular.ttf b/src/features/terminal/renderer/fonts/AnonymousPro-Regular.ttf similarity index 100% rename from src/renderer/fonts/AnonymousPro-Regular.ttf rename to src/features/terminal/renderer/fonts/AnonymousPro-Regular.ttf diff --git a/src/renderer/fonts/IBMPlexMono-Regular.ttf b/src/features/terminal/renderer/fonts/IBMPlexMono-Regular.ttf similarity index 100% rename from src/renderer/fonts/IBMPlexMono-Regular.ttf rename to src/features/terminal/renderer/fonts/IBMPlexMono-Regular.ttf diff --git a/src/renderer/fonts/JetBrainsMono-Regular.ttf b/src/features/terminal/renderer/fonts/JetBrainsMono-Regular.ttf similarity index 100% rename from src/renderer/fonts/JetBrainsMono-Regular.ttf rename to src/features/terminal/renderer/fonts/JetBrainsMono-Regular.ttf diff --git a/src/renderer/fonts/RedHatMono-Regular.ttf b/src/features/terminal/renderer/fonts/RedHatMono-Regular.ttf similarity index 100% rename from src/renderer/fonts/RedHatMono-Regular.ttf rename to src/features/terminal/renderer/fonts/RedHatMono-Regular.ttf diff --git a/src/renderer/fonts/Roboto-Mono-nerd.ttf b/src/features/terminal/renderer/fonts/Roboto-Mono.ttf similarity index 100% rename from src/renderer/fonts/Roboto-Mono-nerd.ttf rename to src/features/terminal/renderer/fonts/Roboto-Mono.ttf diff --git a/src/renderer/fonts/SourceCodePro-Regular.ttf b/src/features/terminal/renderer/fonts/SourceCodePro-Regular.ttf similarity index 100% rename from src/renderer/fonts/SourceCodePro-Regular.ttf rename to src/features/terminal/renderer/fonts/SourceCodePro-Regular.ttf diff --git a/src/renderer/fonts/SpaceMono-Regular.ttf b/src/features/terminal/renderer/fonts/SpaceMono-Regular.ttf similarity index 100% rename from src/renderer/fonts/SpaceMono-Regular.ttf rename to src/features/terminal/renderer/fonts/SpaceMono-Regular.ttf diff --git a/src/renderer/fonts/UbuntuMono-Regular.ttf b/src/features/terminal/renderer/fonts/UbuntuMono-Regular.ttf similarity index 100% rename from src/renderer/fonts/UbuntuMono-Regular.ttf rename to src/features/terminal/renderer/fonts/UbuntuMono-Regular.ttf diff --git a/src/features/terminal/renderer/fonts/anonymous-pro.injectable.ts b/src/features/terminal/renderer/fonts/anonymous-pro.injectable.ts new file mode 100644 index 000000000000..d0a671e5bd9d --- /dev/null +++ b/src/features/terminal/renderer/fonts/anonymous-pro.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import AnonymousPro from "./AnonymousPro-Regular.ttf"; + +const anonymousProTerminalFontInjectable = getInjectable({ + id: "anonymous-pro-terminal-font", + instantiate: () => ({ + name:"Anonymous Pro", + url: AnonymousPro, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default anonymousProTerminalFontInjectable; diff --git a/src/features/terminal/renderer/fonts/fonts.injectable.ts b/src/features/terminal/renderer/fonts/fonts.injectable.ts new file mode 100644 index 000000000000..2c8dc1d57a09 --- /dev/null +++ b/src/features/terminal/renderer/fonts/fonts.injectable.ts @@ -0,0 +1,13 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; + +const terminalFontsInjectable = getInjectable({ + id: "terminal-fonts", + instantiate: (di) => di.injectMany(terminalFontInjectionToken), +}); + +export default terminalFontsInjectable; diff --git a/src/features/terminal/renderer/fonts/ibm-plex-mono.injectable.ts b/src/features/terminal/renderer/fonts/ibm-plex-mono.injectable.ts new file mode 100644 index 000000000000..b75440adbcca --- /dev/null +++ b/src/features/terminal/renderer/fonts/ibm-plex-mono.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import IBMPlexMono from "./IBMPlexMono-Regular.ttf"; + +const ibmPlexMonoTerminalFontInjectable = getInjectable({ + id: "ibm-plex-mono-terminal-font", + instantiate: () => ({ + name: "IBM Plex Mono", + url: IBMPlexMono, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default ibmPlexMonoTerminalFontInjectable; diff --git a/src/features/terminal/renderer/fonts/jetbrains-mono.injectable.ts b/src/features/terminal/renderer/fonts/jetbrains-mono.injectable.ts new file mode 100644 index 000000000000..c86d93d55a55 --- /dev/null +++ b/src/features/terminal/renderer/fonts/jetbrains-mono.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import JetBrainsMono from "./JetBrainsMono-Regular.ttf"; + +const jetbrainsMonoTerminalFontInjectable = getInjectable({ + id: "jetbrains-mono-terminal-font", + instantiate: () => ({ + name: "JetBrains Mono", + url: JetBrainsMono, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default jetbrainsMonoTerminalFontInjectable; diff --git a/src/renderer/components/dock/terminal/terminal-fonts.global-override-for-injectable.ts b/src/features/terminal/renderer/fonts/load-font.global-override-for-injectable.ts similarity index 52% rename from src/renderer/components/dock/terminal/terminal-fonts.global-override-for-injectable.ts rename to src/features/terminal/renderer/fonts/load-font.global-override-for-injectable.ts index eb549af384cd..0d1b23bfde89 100644 --- a/src/renderer/components/dock/terminal/terminal-fonts.global-override-for-injectable.ts +++ b/src/features/terminal/renderer/fonts/load-font.global-override-for-injectable.ts @@ -2,13 +2,8 @@ * 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"; +import loadTerminalFontInjectable from "./load-font.injectable"; -export default getGlobalOverride(preloadAllTerminalFontsInjectable, () => { - return { - id: "", - async run() { - }, - }; -}); +export default getGlobalOverride(loadTerminalFontInjectable, () => async () => {}); diff --git a/src/features/terminal/renderer/fonts/load-font.injectable.ts b/src/features/terminal/renderer/fonts/load-font.injectable.ts new file mode 100644 index 000000000000..920042e5dfff --- /dev/null +++ b/src/features/terminal/renderer/fonts/load-font.injectable.ts @@ -0,0 +1,27 @@ +/** + * 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 type { TerminalFont } from "./token"; + +export type LoadTerminalFont = (font: TerminalFont) => Promise; + +const loadTerminalFontInjectable = getInjectable({ + id: "load-terminal-font", + instantiate: (): LoadTerminalFont => async (font) => { + const fontLoaded = document.fonts.check(`10px ${font.name}`); + + if (fontLoaded) { + return; + } + + const fontFace = new FontFace(font.name, `url(${font.url})`); + + document.fonts.add(fontFace); + await fontFace.load(); + }, + causesSideEffects: true, +}); + +export default loadTerminalFontInjectable; diff --git a/src/features/terminal/renderer/fonts/preload-fonts.injectable.ts b/src/features/terminal/renderer/fonts/preload-fonts.injectable.ts new file mode 100644 index 000000000000..64c40247b7c2 --- /dev/null +++ b/src/features/terminal/renderer/fonts/preload-fonts.injectable.ts @@ -0,0 +1,24 @@ +/** + * 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 "../../../../renderer/before-frame-starts/tokens"; +import terminalFontsInjectable from "./fonts.injectable"; +import loadTerminalFontInjectable from "./load-font.injectable"; + +const preloadTerminalFontsInjectable = getInjectable({ + id: "preload-terminal-fonts", + instantiate: (di) => ({ + id: "preload-terminal-fonts", + run: async () => { + const terminalFonts = di.inject(terminalFontsInjectable); + const loadTerminalFont = di.inject(loadTerminalFontInjectable); + + await Promise.allSettled(terminalFonts.map(loadTerminalFont)); + }, + }), + injectionToken: beforeFrameStartsFirstInjectionToken, +}); + +export default preloadTerminalFontsInjectable; diff --git a/src/features/terminal/renderer/fonts/red-hat-mono.injectable.ts b/src/features/terminal/renderer/fonts/red-hat-mono.injectable.ts new file mode 100644 index 000000000000..4229bc8d1d4c --- /dev/null +++ b/src/features/terminal/renderer/fonts/red-hat-mono.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import RedHatMono from "./RedHatMono-Regular.ttf"; + +const redHatMonoTerminalFontInjectable = getInjectable({ + id: "red-hat-mono-terminal-font", + instantiate: () => ({ + name: "Red Hat Mono", + url: RedHatMono, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default redHatMonoTerminalFontInjectable; diff --git a/src/features/terminal/renderer/fonts/roboto-mono.injectable.ts b/src/features/terminal/renderer/fonts/roboto-mono.injectable.ts new file mode 100644 index 000000000000..e3aa1884861d --- /dev/null +++ b/src/features/terminal/renderer/fonts/roboto-mono.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import RobotoMono from "./Roboto-Mono.ttf"; // patched font with icons + +const robotoMonoTerminalFontInjectable = getInjectable({ + id: "roboto-mono-terminal-font", + instantiate: () => ({ + name: "RobotoMono", + url: RobotoMono, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default robotoMonoTerminalFontInjectable; diff --git a/src/features/terminal/renderer/fonts/source-code-pro.injectable.ts b/src/features/terminal/renderer/fonts/source-code-pro.injectable.ts new file mode 100644 index 000000000000..8b84a275f394 --- /dev/null +++ b/src/features/terminal/renderer/fonts/source-code-pro.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import SourceCodePro from "./SourceCodePro-Regular.ttf"; + +const sourceCodeProTerminalFontInjectable = getInjectable({ + id: "source-code-pro-terminal-font", + instantiate: () => ({ + name: "Source Code Pro", + url: SourceCodePro, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default sourceCodeProTerminalFontInjectable; diff --git a/src/features/terminal/renderer/fonts/space-mono.injectable.ts b/src/features/terminal/renderer/fonts/space-mono.injectable.ts new file mode 100644 index 000000000000..ea2df1c72e9b --- /dev/null +++ b/src/features/terminal/renderer/fonts/space-mono.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import SpaceMono from "./SpaceMono-Regular.ttf"; + +const spaceMonoTerminalFontInjectable = getInjectable({ + id: "space-mono-terminal-font", + instantiate: () => ({ + name: "Space Mono", + url: SpaceMono, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default spaceMonoTerminalFontInjectable; diff --git a/src/features/terminal/renderer/fonts/token.ts b/src/features/terminal/renderer/fonts/token.ts new file mode 100644 index 000000000000..8f90d400e2b1 --- /dev/null +++ b/src/features/terminal/renderer/fonts/token.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { getInjectionToken } from "@ogre-tools/injectable"; + +export interface TerminalFont { + name: string; + url: string; +} + +export const terminalFontInjectionToken = getInjectionToken({ + id: "terminal-font-token", +}); diff --git a/src/features/terminal/renderer/fonts/ubuntu-mono.injectable.ts b/src/features/terminal/renderer/fonts/ubuntu-mono.injectable.ts new file mode 100644 index 000000000000..ab8ffb7b784d --- /dev/null +++ b/src/features/terminal/renderer/fonts/ubuntu-mono.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { terminalFontInjectionToken } from "./token"; +import UbuntuMono from "./UbuntuMono-Regular.ttf"; + +const ubunutuMonoTerminalFontInjectable = getInjectable({ + id: "ubunutu-mono-terminal-font", + instantiate: () => ({ + name: "Ubuntu Mono", + url: UbuntuMono, + }), + injectionToken: terminalFontInjectionToken, +}); + +export default ubunutuMonoTerminalFontInjectable; diff --git a/src/renderer/components/dock/terminal/terminal-fonts.injectable.ts b/src/renderer/components/dock/terminal/terminal-fonts.injectable.ts deleted file mode 100644 index 1609f8b411c3..000000000000 --- a/src/renderer/components/dock/terminal/terminal-fonts.injectable.ts +++ /dev/null @@ -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 { - 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, -}); diff --git a/types/mocks.d.ts b/types/mocks.d.ts index 3826aac8291b..1835be0c2509 100644 --- a/types/mocks.d.ts +++ b/types/mocks.d.ts @@ -32,4 +32,8 @@ declare module "*.png"; declare module "*.eot"; declare module "*.woff"; declare module "*.woff2"; -declare module "*.ttf"; + +declare module "*.ttf" { + const content: string; + export = content; +} From 9f9570c3e80a625ad427115ad4d443ac59faee48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 17 Jan 2023 08:13:23 -0500 Subject: [PATCH 2/2] Bump eslint-plugin-import from 2.27.4 to 2.27.5 (#6953) Bumps [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) from 2.27.4 to 2.27.5. - [Release notes](https://github.com/import-js/eslint-plugin-import/releases) - [Changelog](https://github.com/import-js/eslint-plugin-import/blob/main/CHANGELOG.md) - [Commits](https://github.com/import-js/eslint-plugin-import/compare/v2.27.4...v2.27.5) --- updated-dependencies: - dependency-name: eslint-plugin-import dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 3398b48ade31..c3ef59a3b113 100644 --- a/package.json +++ b/package.json @@ -392,7 +392,7 @@ "eslint": "^8.32.0", "eslint-import-resolver-typescript": "^3.5.3", "eslint-plugin-header": "^3.1.1", - "eslint-plugin-import": "^2.27.4", + "eslint-plugin-import": "^2.27.5", "eslint-plugin-react": "7.32.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-unused-imports": "^2.0.0", diff --git a/yarn.lock b/yarn.lock index 4b676d2ca124..48a826ab86f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3483,7 +3483,7 @@ array.prototype.flat@^1.3.1: es-abstract "^1.20.4" es-shim-unscopables "^1.0.0" -array.prototype.flatmap@^1.3.0, array.prototype.flatmap@^1.3.1: +array.prototype.flatmap@^1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/array.prototype.flatmap/-/array.prototype.flatmap-1.3.1.tgz#1aae7903c2100433cb8261cd4ed310aab5c4a183" integrity sha512-8UGn9O1FDVvMNB0UlLv4voxRMze7+FpHyF5mSMRjWHUMlpoDViniy05870VlxhfgTnLbpuwTzvD76MTtWxB/mQ== @@ -5873,14 +5873,14 @@ eslint-plugin-header@^3.1.1: resolved "https://registry.yarnpkg.com/eslint-plugin-header/-/eslint-plugin-header-3.1.1.tgz#6ce512432d57675265fac47292b50d1eff11acd6" integrity sha512-9vlKxuJ4qf793CmeeSrZUvVClw6amtpghq3CuWcB5cUNnWHQhgcqy5eF8oVKFk1G3Y/CbchGfEaw3wiIJaNmVg== -eslint-plugin-import@^2.27.4: - version "2.27.4" - resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.27.4.tgz#319c2f6f6580e1678d674a258ee5e981c10cc25b" - integrity sha512-Z1jVt1EGKia1X9CnBCkpAOhWy8FgQ7OmJ/IblEkT82yrFU/xJaxwujaTzLWqigewwynRQ9mmHfX9MtAfhxm0sA== +eslint-plugin-import@^2.27.5: + version "2.27.5" + resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz#876a6d03f52608a3e5bb439c2550588e51dd6c65" + integrity sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow== dependencies: array-includes "^3.1.6" array.prototype.flat "^1.3.1" - array.prototype.flatmap "^1.3.0" + array.prototype.flatmap "^1.3.1" debug "^3.2.7" doctrine "^2.1.0" eslint-import-resolver-node "^0.3.7"