fix font importer

This commit is contained in:
Lhc_fl 2024-12-06 01:42:05 +08:00 committed by fly_mc
parent def364088f
commit 436e306cbc
3 changed files with 21 additions and 19 deletions

View file

@ -24,6 +24,7 @@ import { miLocalStorage } from '@/local-storage.js';
import { fetchCustomEmojis } from '@/custom-emojis.js';
import { setupRouter } from '@/router/main.js';
import { createMainRouter } from '@/router/definition.js';
import { loadFontStyle } from '@/scripts/load-font.js';
export async function common(createVue: () => App<Element>) {
console.info(`Misskey v${version}`);
@ -234,13 +235,8 @@ export async function common(createVue: () => App<Element>) {
//#region Load default font
const def_arr = miLocalStorage.getItem('defaultFontFace')?.split('_');
const fontId = def_arr?.[0];
if (fontId && fontId !== 'system-ui') {
try {
await import(`@/styles-font/${fontId}.scss`);
document.documentElement.classList.add(`default-font-${def_arr.join('_')}`);
} catch (e) {
console.warn(`Failed to load font style: ${fontId}`, e);
}
if (fontId) {
loadFontStyle(fontId);
}
//#endregion

View file

@ -1,4 +1,5 @@
import { computed, ref, watch } from 'vue';
import { loadFontStyle } from './load-font.js';
import type { Ref } from 'vue';
import { miLocalStorage } from '@/local-storage.js';
import { i18n } from '@/i18n.js';
@ -52,14 +53,6 @@ function getFontId(name: string, option: string) {
}
}
async function loadFontStyle(fontId: string) {
try {
await import(`@/styles-font/${fontId}.scss`);
} catch (e) {
console.warn(`Failed to load font style: ${fontId}`, e);
}
}
export function getDefaultFontSettings() {
const def_arr = miLocalStorage.getItem('defaultFontFace')?.split('_');
const fontFace = ref(def_arr?.[0] ?? 'system-ui');
@ -76,10 +69,7 @@ export function getDefaultFontSettings() {
miLocalStorage.setItem('defaultFontFace', newFontId);
document.documentElement.classList.add(`default-font-${newFontId}`);
if (fontFace.value !== 'system-ui') {
await loadFontStyle(fontFace.value);
}
console.log(newFontId);
await loadFontStyle(fontFace.value);
}
watch(fontFace, (newVal) => {

View file

@ -0,0 +1,16 @@
const defaultFontsList = [
'roboto',
'misskey-biz',
'arial',
'times',
'system-ui',
];
export async function loadFontStyle(fontId: string) {
if (defaultFontsList.includes(fontId)) return;
try {
await import(`@/styles-font/${fontId}.scss`);
} catch (err) {
console.warn(`Failed to load font style: ${fontId}`, err);
}
}