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

Always preload app fonts at earliest stages #5117

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/renderer/components/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
@tailwind components;
@tailwind utilities;

@import "~flex.box"; // todo: replace with tailwind's flexbox classes
@import "./fonts";
@import "~flex.box";
@import "../themes/theme-vars";
@import "./fonts";

:root {
--unit: 8px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@
*/

.TerminalTab {
@include font-preload {
font-family: "RobotoMono", monospace;
}
}
10 changes: 10 additions & 0 deletions src/renderer/components/fonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@
font-display: block;
src: local('RobotoMono'), url('./fonts/roboto-mono-nerd.ttf') format('truetype');
}

#fonts-preloading {
> .icons {
@include font-preload("Material Icons");
}

> .terminal {
@include font-preload("RobotoMono");
}
}
15 changes: 10 additions & 5 deletions src/renderer/components/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@
}
}

// Makes custom font available at earlier stages (start preloading)
// Element must be in DOM and contain some text of loading font.
@mixin font-preload() {
// Makes custom @font-family available at earlier stages.
// Element must exist in DOM as soon as possible to initiate preloading.
@mixin font-preload($fontFamily) {
position: absolute;
visibility: hidden;
height: 0;

&:before {
width: 0;
display: block;
overflow: hidden;
content: "x"; // required
@content; // must contain `font-family`
content: "x"; // some text required to start applying font in document
font-family: $fontFamily; // imported name in @font-face declaration
@content;
}
}
7 changes: 5 additions & 2 deletions src/renderer/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="preload" href="<%= assetPath %>/MaterialIcons-Regular.ttf" as="font" crossorigin>
<link rel="preload" href="<%= assetPath %>/roboto-mono-nerd.ttf" as="font" crossorigin>
</head>
<body>

<div id="app"></div>
<div id="terminal-init"></div>

<div id="fonts-preloading">
<i class="icons"><!--material icons--></i>
<i class="terminal"><!--roboto mono--></i>
</div>

</body>
</html>