refactor utility/storage.ts

This commit is contained in:
syuilo
2026-03-05 19:07:15 +09:00
parent 2d3262a7c6
commit 293b26c37a
4 changed files with 12 additions and 12 deletions

View File

@@ -30,7 +30,6 @@ import { fetchCustomEmojis } from '@/custom-emojis.js';
import { prefer } from '@/preferences.js';
import { $i } from '@/i.js';
import { launchPlugins } from '@/plugin.js';
import { initializeStoragePersistence } from '@/utility/storage.js';
export async function common(createVue: () => Promise<App<Element>>) {
console.info(`Misskey v${version}`);
@@ -328,10 +327,6 @@ export async function common(createVue: () => Promise<App<Element>>) {
console.error('Failed to launch plugins:', error);
}
// ブラウザストレージ永続化の状態を初期化
// top-level awaitを防ぐために明示的に起動時に確認する
initializeStoragePersistence();
app.mount(rootEl);
// boot.jsのやつを解除

View File

@@ -51,10 +51,12 @@ import { enableAutoBackup, getPreferencesProfileMenu } from '@/preferences/utili
import { store } from '@/store.js';
import { signout } from '@/signout.js';
import { genSearchIndexes } from '@/utility/inapp-search.js';
import { enableStoragePersistence, storagePersisted, storagePersistenceSupported, skipStoragePersistence } from '@/utility/storage.js';
import { enableStoragePersistence, getStoragePersistenceStatusRef, storagePersistenceSupported, skipStoragePersistence } from '@/utility/storage.js';
const searchIndex = await import('search-index:settings').then(({ searchIndexes }) => genSearchIndexes(searchIndexes));
const storagePersisted = await getStoragePersistenceStatusRef();
const indexInfo = {
title: i18n.ts.settings,
icon: 'ti ti-settings',

View File

@@ -165,7 +165,7 @@ import MkKeyValue from '@/components/MkKeyValue.vue';
import MkButton from '@/components/MkButton.vue';
import FormSlot from '@/components/form/slot.vue';
import * as os from '@/os.js';
import { enableStoragePersistence, storagePersisted, storagePersistenceSupported } from '@/utility/storage.js';
import { enableStoragePersistence, getStoragePersistenceStatusRef, storagePersistenceSupported } from '@/utility/storage.js';
import { ensureSignin } from '@/i.js';
import { i18n } from '@/i18n.js';
import { definePage } from '@/page.js';
@@ -180,6 +180,8 @@ import { cloudBackup } from '@/preferences/utility.js';
const $i = ensureSignin();
const storagePersisted = await getStoragePersistenceStatusRef();
const reportError = prefer.model('reportError');
const enableCondensedLine = prefer.model('enableCondensedLine');
const skipNoteRender = prefer.model('skipNoteRender');

View File

@@ -9,13 +9,14 @@ import { store } from '@/store.js';
import { i18n } from '@/i18n.js';
export const storagePersistenceSupported = window.isSecureContext && 'storage' in navigator;
const _storagePersisted = ref(false);
export const storagePersisted = readonly(_storagePersisted);
const storagePersisted = ref(false);
export async function initializeStoragePersistence() {
export async function getStoragePersistenceStatusRef() {
if (storagePersistenceSupported) {
_storagePersisted.value = await navigator.storage.persisted().catch(() => false);
storagePersisted.value = await navigator.storage.persisted().catch(() => false);
}
return readonly(storagePersisted);
}
export async function enableStoragePersistence() {
@@ -23,7 +24,7 @@ export async function enableStoragePersistence() {
try {
const persisted = await navigator.storage.persist();
if (persisted) {
_storagePersisted.value = true;
storagePersisted.value = true;
} else {
os.alert({
type: 'error',