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

Fix: preloading fonts for terminal #4867

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions src/renderer/components/dock/terminal/dock-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/

import "./terminal-dock-tab.scss";
import React from "react";
import { observer } from "mobx-react";
import { boundMethod, cssNames } from "../../../utils";
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/components/dock/terminal/terminal-dock-tab.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/

.TerminalTab {
@include font-preload {
font-family: "RobotoMono", monospace;
}
}
1 change: 1 addition & 0 deletions src/renderer/components/fonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
// https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/RobotoMono
@font-face {
font-family: 'RobotoMono';
font-display: block;
src: local('RobotoMono'), url('./fonts/roboto-mono-nerd.ttf') format('truetype');
}
12 changes: 12 additions & 0 deletions src/renderer/components/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,15 @@
@content; // css-modules (*.module.scss)
}
}

// Makes custom font available at earlier stages (start preloading)
// Element must be in DOM and contain some text of loading font.
@mixin font-preload() {
&:before {
width: 0;
display: block;
overflow: hidden;
content: "x"; // required
@content; // must contain `font-family`
}
}
2 changes: 2 additions & 0 deletions src/renderer/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<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>

Expand Down
15 changes: 6 additions & 9 deletions webpack.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
export function webpackLensRenderer(): webpack.Configuration {
console.info("WEBPACK:renderer", vars);

const {
appName,
buildDir,
htmlTemplate,
isDevelopment,
publicPath,
rendererDir,
} = vars;
const assetsFolderName = "assets";
const { appName, buildDir, htmlTemplate, isDevelopment, publicPath, rendererDir } = vars;

return {
target: "electron-renderer",
Expand All @@ -42,7 +36,7 @@ export function webpackLensRenderer(): webpack.Configuration {
path: buildDir,
filename: "[name].js",
chunkFilename: "chunks/[name].js",
assetModuleFilename: "assets/[name][ext][query]",
assetModuleFilename: `${assetsFolderName}/[name][ext][query]`,
},
watchOptions: {
ignored: /node_modules/, // https://webpack.js.org/configuration/watch/
Expand Down Expand Up @@ -97,6 +91,9 @@ export function webpackLensRenderer(): webpack.Configuration {
template: htmlTemplate,
inject: true,
hash: true,
templateParameters: {
assetPath: `${publicPath}${assetsFolderName}`,
},
}),

new CircularDependencyPlugin({
Expand Down