diff --git a/src/lang/ar-ye.json b/src/lang/ar-ye.json index e3a44699e..7a3f5bd84 100644 --- a/src/lang/ar-ye.json +++ b/src/lang/ar-ye.json @@ -703,5 +703,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/be-by.json b/src/lang/be-by.json index 85d8daf5d..af6a157e5 100644 --- a/src/lang/be-by.json +++ b/src/lang/be-by.json @@ -705,5 +705,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/bn-bd.json b/src/lang/bn-bd.json index 1a14bd20f..81893d242 100644 --- a/src/lang/bn-bd.json +++ b/src/lang/bn-bd.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/cs-cz.json b/src/lang/cs-cz.json index cb2e38fa2..f240703b7 100644 --- a/src/lang/cs-cz.json +++ b/src/lang/cs-cz.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/de-de.json b/src/lang/de-de.json index fb78ad977..dd5bf0cbe 100644 --- a/src/lang/de-de.json +++ b/src/lang/de-de.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/en-us.json b/src/lang/en-us.json index 54c215971..22fe53842 100644 --- a/src/lang/en-us.json +++ b/src/lang/en-us.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/es-sv.json b/src/lang/es-sv.json index 87affdfa9..4880d6b42 100644 --- a/src/lang/es-sv.json +++ b/src/lang/es-sv.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/fr-fr.json b/src/lang/fr-fr.json index ae9caa742..3fe55e0c2 100644 --- a/src/lang/fr-fr.json +++ b/src/lang/fr-fr.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/he-il.json b/src/lang/he-il.json index e6c102149..e0b953942 100644 --- a/src/lang/he-il.json +++ b/src/lang/he-il.json @@ -705,5 +705,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/hi-in.json b/src/lang/hi-in.json index ecd15cb9a..76ea776f2 100644 --- a/src/lang/hi-in.json +++ b/src/lang/hi-in.json @@ -705,5 +705,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/hu-hu.json b/src/lang/hu-hu.json index 21b8fc7bd..97256f8c0 100644 --- a/src/lang/hu-hu.json +++ b/src/lang/hu-hu.json @@ -704,5 +704,7 @@ "pin tab": "Lap rögzítése", "unpin tab": "Lap rögzítésének megszüntetése", "pinned tab": "Rögzített lap", - "unpin tab before closing": "Lap rögzítésének megszüntetése bezárás előtt." + "unpin tab before closing": "Lap rögzítésének megszüntetése bezárás előtt.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/id-id.json b/src/lang/id-id.json index 23d6c64a6..7fd9bf494 100644 --- a/src/lang/id-id.json +++ b/src/lang/id-id.json @@ -705,5 +705,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/ir-fa.json b/src/lang/ir-fa.json index ad461280b..01b90552f 100644 --- a/src/lang/ir-fa.json +++ b/src/lang/ir-fa.json @@ -705,5 +705,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/it-it.json b/src/lang/it-it.json index 4f8fb6102..3bade79e8 100644 --- a/src/lang/it-it.json +++ b/src/lang/it-it.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/ja-jp.json b/src/lang/ja-jp.json index e38ea3923..e3c58a8d2 100644 --- a/src/lang/ja-jp.json +++ b/src/lang/ja-jp.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/ko-kr.json b/src/lang/ko-kr.json index 2d5b1d148..0b553555d 100644 --- a/src/lang/ko-kr.json +++ b/src/lang/ko-kr.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/ml-in.json b/src/lang/ml-in.json index 77e11e892..3eb39e7fe 100644 --- a/src/lang/ml-in.json +++ b/src/lang/ml-in.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/mm-unicode.json b/src/lang/mm-unicode.json index 2cc0185d2..523fc1795 100644 --- a/src/lang/mm-unicode.json +++ b/src/lang/mm-unicode.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/mm-zawgyi.json b/src/lang/mm-zawgyi.json index 3ad486c57..6abca72a4 100644 --- a/src/lang/mm-zawgyi.json +++ b/src/lang/mm-zawgyi.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/pl-pl.json b/src/lang/pl-pl.json index 03a03aa44..a671b035e 100644 --- a/src/lang/pl-pl.json +++ b/src/lang/pl-pl.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/pt-br.json b/src/lang/pt-br.json index 21cee3021..2295e4605 100644 --- a/src/lang/pt-br.json +++ b/src/lang/pt-br.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/pu-in.json b/src/lang/pu-in.json index 642c62d23..4a93ec987 100644 --- a/src/lang/pu-in.json +++ b/src/lang/pu-in.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/ru-ru.json b/src/lang/ru-ru.json index d91a576f7..ef39ac93f 100644 --- a/src/lang/ru-ru.json +++ b/src/lang/ru-ru.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/tl-ph.json b/src/lang/tl-ph.json index 71c5b4d59..6b36beb18 100644 --- a/src/lang/tl-ph.json +++ b/src/lang/tl-ph.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/tr-tr.json b/src/lang/tr-tr.json index 509710e81..1bda02070 100644 --- a/src/lang/tr-tr.json +++ b/src/lang/tr-tr.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/uk-ua.json b/src/lang/uk-ua.json index fb3f9844a..dc272e14f 100644 --- a/src/lang/uk-ua.json +++ b/src/lang/uk-ua.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/uz-uz.json b/src/lang/uz-uz.json index 4550d1b4b..9a0dc0149 100644 --- a/src/lang/uz-uz.json +++ b/src/lang/uz-uz.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/vi-vn.json b/src/lang/vi-vn.json index 9949d4396..9cf5ed3d8 100644 --- a/src/lang/vi-vn.json +++ b/src/lang/vi-vn.json @@ -705,5 +705,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/zh-cn.json b/src/lang/zh-cn.json index 93a16935d..99ed8357c 100644 --- a/src/lang/zh-cn.json +++ b/src/lang/zh-cn.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/zh-hant.json b/src/lang/zh-hant.json index 1ce79ff9d..714173a91 100644 --- a/src/lang/zh-hant.json +++ b/src/lang/zh-hant.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lang/zh-tw.json b/src/lang/zh-tw.json index 0e53a4909..b2e544a54 100644 --- a/src/lang/zh-tw.json +++ b/src/lang/zh-tw.json @@ -704,5 +704,7 @@ "pin tab": "Pin tab", "unpin tab": "Unpin tab", "pinned tab": "Pinned tab", - "unpin tab before closing": "Unpin the tab before closing it." + "unpin tab before closing": "Unpin the tab before closing it.", + "app font": "App font", + "settings-info-app-font-family": "Choose the font used across the app interface." } diff --git a/src/lib/applySettings.js b/src/lib/applySettings.js index 819ec962f..e3b6cbd5e 100644 --- a/src/lib/applySettings.js +++ b/src/lib/applySettings.js @@ -33,7 +33,8 @@ export default { } actions("set-height", settings.quickTools); - fonts.setFont(settings.editorFont); + fonts.setAppFont(settings.appFont); + fonts.setEditorFont(settings.editorFont); if (!themes.applied) { themes.apply("dark"); } diff --git a/src/lib/fonts.js b/src/lib/fonts.js index 0811c59f0..c7f5faa0f 100644 --- a/src/lib/fonts.js +++ b/src/lib/fonts.js @@ -11,6 +11,9 @@ const customFontNames = new Set(); const CUSTOM_FONTS_KEY = "custom_fonts"; const FONT_FACE_STYLE_ID = "font-face-style"; const EDITOR_STYLE_ID = "editor-font-style"; +const APP_STYLE_ID = "app-font-style"; +const DEFAULT_EDITOR_FONT = "Roboto Mono"; +const DEFAULT_APP_FONT_STACK = `"Roboto", sans-serif`; add( "Fira Code", @@ -187,7 +190,11 @@ function has(name) { return fonts.has(name); } -async function setFont(name) { +function isCustom(name) { + return customFontNames.has(name); +} + +async function setEditorFont(name) { loader.showTitleLoader(); try { await loadFont(name); @@ -200,12 +207,35 @@ async function setFont(name) { }`; } catch (error) { toast(`${name} font not found`, "error"); - setFont("Roboto Mono"); + setEditorFont(DEFAULT_EDITOR_FONT); } finally { loader.removeTitleLoader(); } } +async function setAppFont(name) { + const $style = ensureStyleElement(APP_STYLE_ID); + + if (!name) { + $style.textContent = `:root { + --app-font-family: ${DEFAULT_APP_FONT_STACK}; +}`; + return; + } + + try { + await loadFont(name); + $style.textContent = `:root { + --app-font-family: "${name}", ${DEFAULT_APP_FONT_STACK}; +}`; + } catch (error) { + toast(`${name} font not found`, "error"); + $style.textContent = `:root { + --app-font-family: ${DEFAULT_APP_FONT_STACK}; +}`; + } +} + async function downloadFont(name, link) { const FONT_DIR = Url.join(DATA_STORAGE, "fonts"); const FONT_FILE = Url.join(FONT_DIR, name); @@ -268,6 +298,9 @@ export default { getNames, remove, has, - setFont, + isCustom, + setFont: setEditorFont, + setEditorFont, + setAppFont, loadFont, }; diff --git a/src/lib/settings.js b/src/lib/settings.js index 7ee887856..3bfc49005 100644 --- a/src/lib/settings.js +++ b/src/lib/settings.js @@ -137,6 +137,7 @@ class Settings { openFileListPos: this.OPEN_FILE_LIST_POS_HEADER, quickTools: this.#IS_TABLET ? 0 : 1, quickToolsTriggerMode: this.QUICKTOOLS_TRIGGER_MODE_TOUCH, + appFont: "", editorFont: "Roboto Mono", vibrateOnTap: true, fullscreen: false, diff --git a/src/main.scss b/src/main.scss index 124db5738..eab98f5d9 100644 --- a/src/main.scss +++ b/src/main.scss @@ -8,6 +8,7 @@ :root { --scrollbar-width: 4px; + --app-font-family: "Roboto", sans-serif; } * { @@ -32,7 +33,7 @@ body { body { user-select: none; - font-family: "Roboto", sans-serif; + font-family: var(--app-font-family); -webkit-tap-highlight-color: transparent; background-color: #9999ff; background-color: var(--primary-color); diff --git a/src/pages/fontManager/fontManager.js b/src/pages/fontManager/fontManager.js index d466de7c8..cacc792d2 100644 --- a/src/pages/fontManager/fontManager.js +++ b/src/pages/fontManager/fontManager.js @@ -2,23 +2,33 @@ import "./style.scss"; import fsOperation from "fileSystem"; import Page from "components/page"; import searchBar from "components/searchbar"; +import { DEFAULT_TERMINAL_SETTINGS } from "components/terminal"; import toast from "components/toast"; -import alert from "dialogs/alert"; import box from "dialogs/box"; import confirm from "dialogs/confirm"; import loader from "dialogs/loader"; import prompt from "dialogs/prompt"; +import select from "dialogs/select"; import Ref from "html-tag-js/ref"; import actionStack from "lib/actionStack"; import fonts from "lib/fonts"; import appSettings from "lib/settings"; import { hideAd } from "lib/startAd"; import FileBrowser from "pages/fileBrowser"; +import { updateActiveTerminals } from "settings/terminalSettings"; import helpers from "utils/helpers"; import Url from "utils/Url"; export default function fontManager() { - const defaultFont = "Roboto Mono"; + const defaultEditorFont = "Roboto Mono"; + const defaultTerminalFont = DEFAULT_TERMINAL_SETTINGS.fontFamily; + const defaultAppFontLabel = strings.default || "Default"; + const targetLabels = { + app: "App", + editor: "Editor", + terminal: "Terminal", + all: "All", + }; const $page = Page(strings.fonts?.capitalize()); const $search = ; const $addFont = ; @@ -50,21 +60,35 @@ export default function fontManager() { function renderFonts() { const fontNames = fonts.getNames(); - const currentFont = appSettings.value.editorFont || "Roboto Mono"; let $currentItem; + const content = []; + const defaultAppliedTargets = getAppliedTargets(""); + + const $defaultItem = ( + chooseApplyTarget("")} + /> + ); + if (defaultAppliedTargets.length) $currentItem = $defaultItem; + content.push($defaultItem); - const content = fontNames.map((fontName) => { - const isCurrent = fontName === currentFont; + fontNames.forEach((fontName) => { + const appliedTargets = getAppliedTargets(fontName); const $item = ( selectFont(fontName)} + appliedTargets={appliedTargets} + deletable={fonts.isCustom(fontName)} + onSelect={() => chooseApplyTarget(fontName)} onDelete={() => deleteFont(fontName)} /> ); - if (isCurrent) $currentItem = $item; - return $item; + if (!$currentItem && appliedTargets.length) $currentItem = $item; + content.push($item); }); list.el.content = content; @@ -206,21 +230,131 @@ export default function fontManager() { }); } - async function selectFont(fontName) { + function getAppliedTargets(fontName) { + const appFont = appSettings.value.appFont || ""; + const editorFont = appSettings.value.editorFont || defaultEditorFont; + const terminalFont = + appSettings.value.terminalSettings?.fontFamily || defaultTerminalFont; + const appliedTargets = []; + + if (fontName) { + if (appFont === fontName) appliedTargets.push("app"); + if (editorFont === fontName) appliedTargets.push("editor"); + if (terminalFont === fontName) appliedTargets.push("terminal"); + return appliedTargets; + } + + if (!appFont) appliedTargets.push("app"); + return appliedTargets; + } + + function getTargetOptionText(fontName, target) { + if (fontName) { + return `Apply to ${targetLabels[target]}`; + } + + switch (target) { + case "app": + return "Reset App font"; + case "editor": + return "Reset Editor font"; + case "terminal": + return "Reset Terminal font"; + case "all": + return "Reset all fonts"; + default: + return "Reset font"; + } + } + + async function chooseApplyTarget(fontName) { + const title = fontName + ? `Apply "${fontName}"` + : `${defaultAppFontLabel} font`; + + const target = await select( + title, + [ + ["app", getTargetOptionText(fontName, "app")], + ["editor", getTargetOptionText(fontName, "editor")], + ["terminal", getTargetOptionText(fontName, "terminal")], + ["all", getTargetOptionText(fontName, "all")], + ], + true, + ).catch(() => null); + + if (!target) return; + + await applyFontToTarget(fontName, target); + } + + async function applyFontToTarget(fontName, target) { try { - await fonts.setFont(fontName); - appSettings.update({ editorFont: fontName }, false); - toast(`Font changed to "${fontName}"`); - renderFonts(); // Refresh to update current selection + const nextEditorFont = fontName || defaultEditorFont; + const nextTerminalFont = fontName || defaultTerminalFont; + const nextTerminalSettings = { + ...(appSettings.value.terminalSettings || DEFAULT_TERMINAL_SETTINGS), + }; + const nextSettings = {}; + + switch (target) { + case "app": + await fonts.setAppFont(fontName); + nextSettings.appFont = fontName; + break; + + case "editor": + await fonts.setEditorFont(nextEditorFont); + nextSettings.editorFont = nextEditorFont; + break; + + case "terminal": + nextTerminalSettings.fontFamily = nextTerminalFont; + nextSettings.terminalSettings = nextTerminalSettings; + await updateActiveTerminals("fontFamily", nextTerminalFont); + break; + + case "all": + await fonts.setAppFont(fontName); + await fonts.setEditorFont(nextEditorFont); + nextTerminalSettings.fontFamily = nextTerminalFont; + await updateActiveTerminals("fontFamily", nextTerminalFont); + nextSettings.appFont = fontName; + nextSettings.editorFont = nextEditorFont; + nextSettings.terminalSettings = nextTerminalSettings; + break; + + default: + return; + } + + await appSettings.update(nextSettings, false); + toast(getApplyToast(fontName, target)); + renderFonts(); } catch (error) { - toast("Failed to set font: " + error.message); + toast("Failed to apply font: " + error.message); + } + } + + function getApplyToast(fontName, target) { + const label = fontName ? `"${fontName}"` : "default font"; + switch (target) { + case "app": + return `${label} applied to app`; + case "editor": + return `${label} applied to editor`; + case "terminal": + return `${label} applied to terminal`; + case "all": + return `${label} applied to app, editor, and terminal`; + default: + return "Font applied"; } } async function deleteFont(fontName) { // Don't allow deleting default fonts - const defaultFonts = ["Fira Code", "Roboto Mono", "MesloLGS NF Regular"]; - if (defaultFonts.includes(fontName)) { + if (!fonts.isCustom(fontName)) { toast("Cannot delete default fonts"); return; } @@ -232,9 +366,14 @@ export default function fontManager() { if (shouldDelete) { try { - // Check if we're deleting the currently active font - const currentFont = appSettings.value.editorFont || "Roboto Mono"; - const isCurrentFont = fontName === currentFont; + const currentEditorFont = + appSettings.value.editorFont || defaultEditorFont; + const currentAppFont = appSettings.value.appFont || ""; + const currentTerminalFont = + appSettings.value.terminalSettings?.fontFamily || defaultTerminalFont; + const isCurrentEditorFont = fontName === currentEditorFont; + const isCurrentAppFont = fontName === currentAppFont; + const isCurrentTerminalFont = fontName === currentTerminalFont; // Remove from fonts collection fonts.remove(fontName); @@ -249,11 +388,46 @@ export default function fontManager() { await fs.delete(); } - // If we deleted the current font, switch to default font (Roboto Mono) - if (isCurrentFont) { - await fonts.setFont(defaultFont); - appSettings.update({ editorFont: defaultFont }, false); - toast(`Font "${fontName}" deleted, switched to ${defaultFont}`); + if (isCurrentAppFont) { + await fonts.setAppFont(""); + } + + if (isCurrentEditorFont) { + await fonts.setEditorFont(defaultEditorFont); + } + + if (isCurrentTerminalFont) { + await updateActiveTerminals("fontFamily", defaultTerminalFont); + } + + if (isCurrentAppFont || isCurrentEditorFont || isCurrentTerminalFont) { + await appSettings.update( + { + ...(isCurrentAppFont ? { appFont: "" } : {}), + ...(isCurrentEditorFont ? { editorFont: defaultEditorFont } : {}), + ...(isCurrentTerminalFont + ? { + terminalSettings: { + ...(appSettings.value.terminalSettings || + DEFAULT_TERMINAL_SETTINGS), + fontFamily: defaultTerminalFont, + }, + } + : {}), + }, + false, + ); + } + + if (isCurrentAppFont || isCurrentEditorFont || isCurrentTerminalFont) { + const restoredTargets = [ + isCurrentAppFont ? "app" : null, + isCurrentEditorFont ? "editor" : null, + isCurrentTerminalFont ? "terminal" : null, + ].filter(Boolean); + toast( + `Font "${fontName}" deleted, restored ${restoredTargets.join(", ")} font defaults`, + ); } else { toast(`Font "${fontName}" deleted`); } @@ -261,20 +435,48 @@ export default function fontManager() { renderFonts(); } catch (error) { // Font removed from collection even if file deletion fails - const currentFont = appSettings.value.editorFont || "Roboto Mono"; - const isCurrentFont = fontName === currentFont; - - // If we deleted the current font, switch to default font (Roboto Mono) - if (isCurrentFont) { + const currentEditorFont = + appSettings.value.editorFont || defaultEditorFont; + const currentAppFont = appSettings.value.appFont || ""; + const currentTerminalFont = + appSettings.value.terminalSettings?.fontFamily || defaultTerminalFont; + const isCurrentEditorFont = fontName === currentEditorFont; + const isCurrentAppFont = fontName === currentAppFont; + const isCurrentTerminalFont = fontName === currentTerminalFont; + + if (isCurrentAppFont || isCurrentEditorFont || isCurrentTerminalFont) { try { - await fonts.setFont(defaultFont); - appSettings.update({ editorFont: defaultFont }, false); - toast( - `Font "${fontName}" deleted, switched to ${defaultFont} (file cleanup may have failed)`, + if (isCurrentAppFont) { + await fonts.setAppFont(""); + } + if (isCurrentEditorFont) { + await fonts.setEditorFont(defaultEditorFont); + } + if (isCurrentTerminalFont) { + await updateActiveTerminals("fontFamily", defaultTerminalFont); + } + await appSettings.update( + { + ...(isCurrentAppFont ? { appFont: "" } : {}), + ...(isCurrentEditorFont + ? { editorFont: defaultEditorFont } + : {}), + ...(isCurrentTerminalFont + ? { + terminalSettings: { + ...(appSettings.value.terminalSettings || + DEFAULT_TERMINAL_SETTINGS), + fontFamily: defaultTerminalFont, + }, + } + : {}), + }, + false, ); + toast(`Font "${fontName}" deleted (file cleanup may have failed)`); } catch (setFontError) { toast( - `Font "${fontName}" deleted, but failed to switch to ${defaultFont}`, + `Font "${fontName}" deleted, but failed to restore a fallback font`, ); } } else { @@ -286,33 +488,47 @@ export default function fontManager() { } } - function FontItem({ name, isCurrent, onSelect, onDelete }) { - const defaultFonts = ["Fira Code", "Roboto Mono", "MesloLGS NF Regular"]; - const isDefault = defaultFonts.includes(name); - const subtitle = isCurrent - ? "Current editor font" - : isDefault - ? "Built-in font" - : "Custom font"; + function FontItem({ + name, + appliedTargets, + subtitle, + deletable = true, + onSelect, + onDelete, + }) { + const isBuiltIn = name !== defaultAppFontLabel && !fonts.isCustom(name); + const isApplied = appliedTargets.length > 0; + const resolvedSubtitle = + subtitle || + (isApplied + ? "Applied font" + : isBuiltIn + ? "Built-in font" + : "Custom font"); const $item = (
{name}
- {subtitle} + {resolvedSubtitle}
- {isCurrent || !isDefault ? ( + {appliedTargets.length || deletable ? (
- {isCurrent ? ( - Current - ) : null} - {!isDefault ? ( + {appliedTargets.map((target) => ( + + {targetLabels[target]} + + ))} + {deletable ? ( { const $target = e.target; const action = $target.dataset.action; - if (action === "delete" && !isDefault) { + if (action === "delete" && deletable) { e.stopPropagation(); onDelete(); } else if ( diff --git a/src/pages/fontManager/style.scss b/src/pages/fontManager/style.scss index 2228ced44..d67e1b0ab 100644 --- a/src/pages/fontManager/style.scss +++ b/src/pages/fontManager/style.scss @@ -119,12 +119,31 @@ wc-page.font-manager-page { } } - .font-manager-current { + .font-manager-badge { display: inline-flex; align-items: center; + justify-content: center; + padding: 0.16rem 0.48rem; + border-radius: 999px; font-size: 0.82rem; font-weight: 600; line-height: 1.2; + background: color-mix(in srgb, var(--secondary-color), var(--active-color) 10%); + color: color-mix(in srgb, var(--active-color), transparent 12%); + } + + .font-manager-badge-editor { + background: color-mix(in srgb, var(--secondary-color), #4ca3ff 14%); + color: color-mix(in srgb, #4ca3ff, white 4%); + } + + .font-manager-badge-terminal { + background: color-mix(in srgb, var(--secondary-color), #21b36b 14%); + color: color-mix(in srgb, #21b36b, white 4%); + } + + .font-manager-badge-app { + background: color-mix(in srgb, var(--secondary-color), var(--active-color) 12%); color: color-mix(in srgb, var(--active-color), transparent 14%); } diff --git a/src/settings/appSettings.js b/src/settings/appSettings.js index 102ad025e..9734dee3b 100644 --- a/src/settings/appSettings.js +++ b/src/settings/appSettings.js @@ -7,6 +7,7 @@ import select from "dialogs/select"; import actions from "handlers/quickTools"; import actionStack from "lib/actionStack"; import constants from "lib/constants"; +import fonts from "lib/fonts"; import lang from "lib/lang"; import openFile from "lib/openFile"; import appSettings from "lib/settings"; @@ -19,6 +20,11 @@ import Url from "utils/Url"; export default function otherSettings() { const values = appSettings.value; const title = strings["app settings"].capitalize(); + const appFontText = strings["app font"] || "App font"; + const appFontInfo = + strings["settings-info-app-font-family"] || + "Choose the font used across the app interface."; + const defaultFontLabel = strings.default || "Default"; const categories = { interface: strings["settings-category-interface"], fonts: strings["settings-category-fonts"], @@ -153,6 +159,17 @@ export default function otherSettings() { info: strings["settings-info-app-touch-move-threshold"], category: categories.interface, }, + { + key: "appFont", + text: appFontText, + value: values.appFont || "", + valueText: (value) => value || defaultFontLabel, + get select() { + return [["", defaultFontLabel], ...fonts.getNames()]; + }, + info: appFontInfo, + category: categories.fonts, + }, { key: "fontManager", text: strings["fonts"], @@ -299,6 +316,10 @@ export default function otherSettings() { FontManager(); return; + case "appFont": + await fonts.setAppFont(value); + break; + case "console": { if (value !== "eruda") { break; diff --git a/src/settings/terminalSettings.js b/src/settings/terminalSettings.js index ca435600e..515c2ae0c 100644 --- a/src/settings/terminalSettings.js +++ b/src/settings/terminalSettings.js @@ -367,7 +367,7 @@ export default function terminalSettings() { * @param {string} key * @param {any} value */ -async function updateActiveTerminals(key, value) { +export async function updateActiveTerminals(key, value) { // Find all terminal tabs and update their settings const terminalTabs = editorManager.files.filter( (file) => file.type === "terminal", diff --git a/src/styles/console.m.scss b/src/styles/console.m.scss index dba6fed98..8ff4d63b1 100644 --- a/src/styles/console.m.scss +++ b/src/styles/console.m.scss @@ -40,7 +40,7 @@ c-console { background-color: #313131; z-index: 99998; color: #eeeeee; - font-family: "Roboto", sans-serif; + font-family: var(--app-font-family); } c-console[title] { @@ -318,4 +318,4 @@ c-table c-cell:not(:last-child) { opacity: 1; transform: translate3d(0, 0, 0) } -} \ No newline at end of file +} diff --git a/src/styles/list.scss b/src/styles/list.scss index 3de6ea01e..1f35b615b 100644 --- a/src/styles/list.scss +++ b/src/styles/list.scss @@ -74,7 +74,7 @@ .icon.lang { padding-right: 5px; - font-family: "Roboto", sans-serif; + font-family: var(--app-font-family); font-weight: bolder; color: rgb(37, 37, 37); color: var(--secondary-text-color); @@ -277,4 +277,4 @@ ul { &:focus { background-color: rgba($color: #000000, $alpha: 0.2); } -} \ No newline at end of file +}