fix circular reference between i.ts, instance.ts, and misskeyApi.ts

This commit is contained in:
Hazelnoot 2025-05-30 12:35:26 -04:00
parent c13beacb3a
commit 5818a89ba0
9 changed files with 21 additions and 20 deletions

View file

@ -3,11 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { computed, reactive } from 'vue';
import { computed, nextTick, reactive } from 'vue';
import * as Misskey from 'misskey-js';
import { misskeyApi } from '@/utility/misskey-api.js';
import { miLocalStorage } from '@/local-storage.js';
import { DEFAULT_INFO_IMAGE_URL, DEFAULT_NOT_FOUND_IMAGE_URL, DEFAULT_SERVER_ERROR_IMAGE_URL } from '@@/js/const.js';
import { $i } from '@/i';
// TODO: 他のタブと永続化されたstateを同期
@ -38,6 +39,8 @@ export const notFoundImageUrl = computed(() => instance.notFoundImageUrl ?? DEFA
export const isEnabledUrlPreview = computed(() => instance.enableUrlPreview ?? true);
export const policies = computed<Misskey.entities.RolePolicies>(() => $i?.policies ?? instance.policies);
export async function fetchInstance(force = false): Promise<Misskey.entities.MetaDetailed> {
if (!force) {
const cachedAt = miLocalStorage.getItem('instanceCachedAt') ? parseInt(miLocalStorage.getItem('instanceCachedAt')!) : 0;
@ -60,3 +63,6 @@ export async function fetchInstance(force = false): Promise<Misskey.entities.Met
return instance;
}
// instance export can be empty sometimes, which causes problems.
nextTick(() => fetchInstance());