Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling loading terminal fonts #6913

Merged
merged 3 commits into from
Jan 13, 2023
Merged

Conversation

ixrock
Copy link
Contributor

@ixrock ixrock commented Jan 11, 2023

Moving out from loading fonts only by CSS to JS with FontFace.load() interface due rendering terminal on canvas and since it's more reliable/controllable way of loading font files in general).

Screen.Recording.2023-01-11.at.20.04.17.mov

close #5019

@ixrock ixrock added the bug Something isn't working label Jan 11, 2023
@ixrock ixrock added this to the 6.4.0 milestone Jan 11, 2023
@ixrock ixrock self-assigned this Jan 11, 2023
@ixrock ixrock requested a review from a team as a code owner January 11, 2023 18:19
@ixrock ixrock requested review from jansav, Nokel81 and aleksfront and removed request for a team January 11, 2023 18:19
@ixrock ixrock force-pushed the fix/terminal_fonts_loading branch 2 times, most recently from 28059c3 to cb140c9 Compare January 12, 2023 13:29
@ixrock ixrock force-pushed the fix/terminal_fonts_loading branch from cb140c9 to e3961ad Compare January 12, 2023 13:30
@ixrock ixrock force-pushed the fix/terminal_fonts_loading branch from 6232894 to 4a271d5 Compare January 12, 2023 16:24
"Source Code Pro", "Space Mono", "Ubuntu Mono",
].map(customFont => {
({ userStore, logger, terminalFonts }: Dependencies) => {
const bundledFonts: SelectOption<string>[] = Array.from(terminalFonts.keys()).map(font => {
const { fontFamily, fontSize } = userStore.terminalConfig;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this line could be moved to outside the .map(() => {...}) which could simplify the code

@@ -9,7 +9,8 @@ import type { TabId } from "../dock/store";
import type { TerminalApi } from "../../../api/terminal-api";
import terminalSpawningPoolInjectable from "./terminal-spawning-pool.injectable";
import terminalConfigInjectable from "../../../../common/user-store/terminal-config.injectable";
import terminalCopyOnSelectInjectable from "../../../../common/user-store/terminal-copy-on-select.injectable";
import terminalCopyOnSelectInjectable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file probably doesn't need to be changed in this PR


export default getGlobalOverride(preloadAllTerminalFontsInjectable, () => {
return {
id: "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be a good idea to keep the same id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally didn't put any id to avoid duplication and keeping in sync with the injectable in future (it feels like it should not be responsible for this, maybe we should not ask id at all and use it from passed injectable automatically) cc @jansav

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ID is different from the Injectable ID because it is part of the data which is created, same as any other field (could have been call name).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's different? If I duplicate the string it would be the same. Moreover, we can use different ID from returned object (from runnable):

export const preloadAllTerminalFontsInjectable = getInjectable({
  id: "preloadAllTerminalFontsInjectable",

  instantiate(di) {
    const terminalFonts = di.inject(terminalFontsInjectable);
    const preloadFont = di.inject(preloadTerminalFontInjectable);

    return {
      id: "preload-all-terminal-fonts", // <--- THAT ONE

      async run() {
        await Promise.allSettled(
          Array.from(terminalFonts.keys()).map(preloadFont),
        );
      },
    };
  },

  injectionToken: beforeFrameStartsFirstInjectionToken,

  causesSideEffects: true,
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id: "preload-all-terminal-fonts", // <--- THAT ONE This is the one that I am talking about

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean this ID should be utilized automatically from passed injectable to make id optional.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough that would be nicer indeed

id: "terminalFontsInjectable",

instantiate() {
return new Map([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: either this map should be created from a call to di.injectMany(terminalFontInjectionToken) (for some new injection token) and then be fully OCP or it doesn't need to be wrapped in an injectable.


injectionToken: beforeFrameStartsFirstInjectionToken,

causesSideEffects: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually on further note, given that preloadTerminalFont is causesSideEffects: true this one doesn't have to be since it doesn't introduce any new side effects.

@Nokel81
Copy link
Collaborator

Nokel81 commented Jan 13, 2023

Merging, the above comments can be resolved in a future PR

@Nokel81 Nokel81 merged commit 875972e into master Jan 13, 2023
@Nokel81 Nokel81 deleted the fix/terminal_fonts_loading branch January 13, 2023 14:14
@Nokel81 Nokel81 mentioned this pull request Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RobotoMono font not loaded when terminal opened first time
3 participants