Skip to content

Commit 6559c0b

Browse files
committed
feat(fonts): add target-based font assignments in font manager and option to set app font
1 parent 25bdf3a commit 6559c0b

File tree

10 files changed

+339
-62
lines changed

10 files changed

+339
-62
lines changed

src/lib/applySettings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export default {
3333
}
3434

3535
actions("set-height", settings.quickTools);
36-
fonts.setFont(settings.editorFont);
36+
fonts.setAppFont(settings.appFont);
37+
fonts.setEditorFont(settings.editorFont);
3738
if (!themes.applied) {
3839
themes.apply("dark");
3940
}

src/lib/fonts.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const customFontNames = new Set();
1111
const CUSTOM_FONTS_KEY = "custom_fonts";
1212
const FONT_FACE_STYLE_ID = "font-face-style";
1313
const EDITOR_STYLE_ID = "editor-font-style";
14+
const APP_STYLE_ID = "app-font-style";
15+
const DEFAULT_EDITOR_FONT = "Roboto Mono";
16+
const DEFAULT_APP_FONT_STACK = `"Roboto", sans-serif`;
1417

1518
add(
1619
"Fira Code",
@@ -187,7 +190,11 @@ function has(name) {
187190
return fonts.has(name);
188191
}
189192

190-
async function setFont(name) {
193+
function isCustom(name) {
194+
return customFontNames.has(name);
195+
}
196+
197+
async function setEditorFont(name) {
191198
loader.showTitleLoader();
192199
try {
193200
await loadFont(name);
@@ -200,12 +207,35 @@ async function setFont(name) {
200207
}`;
201208
} catch (error) {
202209
toast(`${name} font not found`, "error");
203-
setFont("Roboto Mono");
210+
setEditorFont(DEFAULT_EDITOR_FONT);
204211
} finally {
205212
loader.removeTitleLoader();
206213
}
207214
}
208215

216+
async function setAppFont(name) {
217+
const $style = ensureStyleElement(APP_STYLE_ID);
218+
219+
if (!name) {
220+
$style.textContent = `:root {
221+
--app-font-family: ${DEFAULT_APP_FONT_STACK};
222+
}`;
223+
return;
224+
}
225+
226+
try {
227+
await loadFont(name);
228+
$style.textContent = `:root {
229+
--app-font-family: "${name}", ${DEFAULT_APP_FONT_STACK};
230+
}`;
231+
} catch (error) {
232+
toast(`${name} font not found`, "error");
233+
$style.textContent = `:root {
234+
--app-font-family: ${DEFAULT_APP_FONT_STACK};
235+
}`;
236+
}
237+
}
238+
209239
async function downloadFont(name, link) {
210240
const FONT_DIR = Url.join(DATA_STORAGE, "fonts");
211241
const FONT_FILE = Url.join(FONT_DIR, name);
@@ -268,6 +298,9 @@ export default {
268298
getNames,
269299
remove,
270300
has,
271-
setFont,
301+
isCustom,
302+
setFont: setEditorFont,
303+
setEditorFont,
304+
setAppFont,
272305
loadFont,
273306
};

src/lib/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class Settings {
137137
openFileListPos: this.OPEN_FILE_LIST_POS_HEADER,
138138
quickTools: this.#IS_TABLET ? 0 : 1,
139139
quickToolsTriggerMode: this.QUICKTOOLS_TRIGGER_MODE_TOUCH,
140+
appFont: "",
140141
editorFont: "Roboto Mono",
141142
vibrateOnTap: true,
142143
fullscreen: false,

src/main.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
:root {
1010
--scrollbar-width: 4px;
11+
--app-font-family: "Roboto", sans-serif;
1112
}
1213

1314
* {
@@ -32,7 +33,7 @@ body {
3233

3334
body {
3435
user-select: none;
35-
font-family: "Roboto", sans-serif;
36+
font-family: var(--app-font-family);
3637
-webkit-tap-highlight-color: transparent;
3738
background-color: #9999ff;
3839
background-color: var(--primary-color);

0 commit comments

Comments
 (0)