fix default fonts

This commit is contained in:
fly_mc 2024-11-30 00:11:45 +08:00
parent b9c765d904
commit b92aca60c1
3 changed files with 18 additions and 18 deletions

View file

@ -62,7 +62,7 @@ async function main() {
} }
//#endregion //#endregion
const fontSize = localStorage.getItem('fontSize') || 1; const fontSize = localStorage.getItem('fontSize') ?? 2;
if (fontSize) { if (fontSize) {
document.documentElement.classList.add('f-' + fontSize); document.documentElement.classList.add('f-' + fontSize);
} }

View file

@ -231,6 +231,19 @@ export async function common(createVue: () => App<Element>) {
} }
//#endregion //#endregion
//#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);
}
}
//#endregion
try { try {
await fetchCustomEmojis(); await fetchCustomEmojis();
} catch (err) { /* empty */ } } catch (err) { /* empty */ }
@ -294,19 +307,6 @@ export async function common(createVue: () => App<Element>) {
console.log(i18n.tsx._selfXssPrevention.description3({ link: 'https://misskey-hub.net/docs/for-users/resources/self-xss/' })); console.log(i18n.tsx._selfXssPrevention.description3({ link: 'https://misskey-hub.net/docs/for-users/resources/self-xss/' }));
//#endregion //#endregion
//#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);
}
}
//#endregion
return { return {
isClientUpdated, isClientUpdated,
app, app,

View file

@ -62,11 +62,11 @@ async function loadFontStyle(fontId: string) {
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] ?? 'maokentangyuan'); const fontFace = ref(def_arr?.[0] ?? 'system-ui');
const fontFaceType = ref(def_arr?.[1] ?? ''); const fontFaceType = ref(def_arr?.[1] ?? '');
const availableTypes = computed(() => getFontOptionsList(fontFace.value)); const availableTypes = computed(() => getFontOptionsList(fontFace.value));
async function setDafaultFont() { async function setDefaultFont() {
for (const klass of [...document.documentElement.classList.values()]) { for (const klass of [...document.documentElement.classList.values()]) {
if (klass.startsWith('default-font-')) { if (klass.startsWith('default-font-')) {
document.documentElement.classList.remove(klass); document.documentElement.classList.remove(klass);
@ -87,11 +87,11 @@ export function getDefaultFontSettings() {
if (optionsList.length !== 0) { if (optionsList.length !== 0) {
fontFaceType.value = optionsList.find((v) => v.default)?.id ?? ''; fontFaceType.value = optionsList.find((v) => v.default)?.id ?? '';
} else { } else {
setDafaultFont(); setDefaultFont();
} }
}); });
watch(fontFaceType, () => { watch(fontFaceType, () => {
setDafaultFont(); setDefaultFont();
}); });
return ref({ return ref({