Skip to content

Commit 4a1ec41

Browse files
committed
refactor: move applyFontFamily to ui.ts
1 parent 69e96f2 commit 4a1ec41

4 files changed

Lines changed: 30 additions & 29 deletions

File tree

frontend/src/ts/commandline/lists/font-family.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Command } from "../types";
22
import { buildCommandForConfigKey } from "../util";
33
import FileStorage from "../../utils/file-storage";
4-
import { applyFontFamily } from "../../controllers/theme-controller";
4+
55
import { updateUI } from "../../elements/settings/custom-font-picker";
66
import { showNoticeNotification } from "../../states/notifications";
77
import { Config } from "../../config/store";
88
import { setConfig } from "../../config/setters";
9+
import { applyFontFamily } from "../../ui";
910
const fromMeta = buildCommandForConfigKey("fontFamily");
1011

1112
if (fromMeta.subgroup) {

frontend/src/ts/controllers/theme-controller.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -294,32 +294,6 @@ export async function applyCustomBackground(): Promise<void> {
294294
}
295295
}
296296

297-
export async function applyFontFamily(): Promise<void> {
298-
let font = Config.fontFamily.replace(/_/g, " ");
299-
300-
const localFont = await fileStorage.getFile("LocalFontFamilyFile");
301-
if (localFont === undefined) {
302-
//use config font
303-
qs(".customFont")?.empty();
304-
} else {
305-
font = "LOCALCUSTOM";
306-
307-
qs(".customFont")?.setHtml(`
308-
@font-face{
309-
font-family: LOCALCUSTOM;
310-
src: url(${localFont});
311-
font-weight: 400;
312-
font-style: normal;
313-
font-display: block;
314-
}`);
315-
}
316-
317-
document.documentElement.style.setProperty(
318-
"--font",
319-
`"${font}", "Roboto Mono", "Vazirharf", monospace`,
320-
);
321-
}
322-
323297
window
324298
.matchMedia?.("(prefers-color-scheme: dark)")
325299
?.addEventListener?.("change", (event) => {

frontend/src/ts/elements/settings/custom-font-picker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import FileStorage from "../../utils/file-storage";
22
import { showNoticeNotification } from "../../states/notifications";
3-
import { applyFontFamily } from "../../controllers/theme-controller";
3+
import { applyFontFamily } from "../../ui";
44

55
const parentEl = document.querySelector(
66
".pageSettings .section[data-config-name='fontFamily']",

frontend/src/ts/ui.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { isDevEnvironment } from "./utils/env";
1010
import { isCustomTextLong } from "./legacy-states/custom-text-name";
1111
import { canQuickRestart } from "./utils/quick-restart";
1212
import { FontName } from "@monkeytype/schemas/fonts";
13-
import { applyFontFamily } from "./controllers/theme-controller";
1413
import { qs, qsr } from "./utils/dom";
1514
import { createEffect } from "solid-js";
15+
import fileStorage from "./utils/file-storage";
1616
import { convertRemToPixels } from "./utils/numbers";
1717

1818
let isPreviewingFont = false;
@@ -27,6 +27,32 @@ export function previewFontFamily(font: FontName): void {
2727
isPreviewingFont = true;
2828
}
2929

30+
export async function applyFontFamily(): Promise<void> {
31+
let font = Config.fontFamily.replace(/_/g, " ");
32+
33+
const localFont = await fileStorage.getFile("LocalFontFamilyFile");
34+
if (localFont === undefined) {
35+
//use config font
36+
qs(".customFont")?.empty();
37+
} else {
38+
font = "LOCALCUSTOM";
39+
40+
qs(".customFont")?.setHtml(`
41+
@font-face{
42+
font-family: LOCALCUSTOM;
43+
src: url(${localFont});
44+
font-weight: 400;
45+
font-style: normal;
46+
font-display: block;
47+
}`);
48+
}
49+
50+
document.documentElement.style.setProperty(
51+
"--font",
52+
`"${font}", "Roboto Mono", "Vazirharf", monospace`,
53+
);
54+
}
55+
3056
export function clearFontPreview(): void {
3157
if (!isPreviewingFont) return;
3258
previewFontFamily(Config.fontFamily);

0 commit comments

Comments
 (0)