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 { fetchCustomEmojis } from '@/custom-emojis.js';
import { setupRouter } from '@/router/main.js'; import { setupRouter } from '@/router/main.js';
import { createMainRouter } from '@/router/definition.js'; import { createMainRouter } from '@/router/definition.js';
import { loadFontStyle } from '@/scripts/load-font.js';
export async function common(createVue: () => App<Element>) { export async function common(createVue: () => App<Element>) {
console.info(`Misskey v${version}`); console.info(`Misskey v${version}`);
@ -234,13 +235,8 @@ export async function common(createVue: () => App<Element>) {
//#region Load default font //#region Load default font
const def_arr = miLocalStorage.getItem('defaultFontFace')?.split('_'); const def_arr = miLocalStorage.getItem('defaultFontFace')?.split('_');
const fontId = def_arr?.[0]; const fontId = def_arr?.[0];
if (fontId && fontId !== 'system-ui') { if (fontId) {
try { loadFontStyle(fontId);
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);
}
} }
//#endregion //#endregion

View file

@ -1,4 +1,5 @@
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
import { loadFontStyle } from './load-font.js';
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { miLocalStorage } from '@/local-storage.js'; import { miLocalStorage } from '@/local-storage.js';
import { i18n } from '@/i18n.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() { export function getDefaultFontSettings() {
const def_arr = miLocalStorage.getItem('defaultFontFace')?.split('_'); const def_arr = miLocalStorage.getItem('defaultFontFace')?.split('_');
const fontFace = ref(def_arr?.[0] ?? 'system-ui'); const fontFace = ref(def_arr?.[0] ?? 'system-ui');
@ -76,11 +69,8 @@ export function getDefaultFontSettings() {
miLocalStorage.setItem('defaultFontFace', newFontId); miLocalStorage.setItem('defaultFontFace', newFontId);
document.documentElement.classList.add(`default-font-${newFontId}`); document.documentElement.classList.add(`default-font-${newFontId}`);
if (fontFace.value !== 'system-ui') {
await loadFontStyle(fontFace.value); await loadFontStyle(fontFace.value);
} }
console.log(newFontId);
}
watch(fontFace, (newVal) => { watch(fontFace, (newVal) => {
const optionsList = getFontOptionsList(newVal); const optionsList = getFontOptionsList(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);
}
}