mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-03-21 03:30:42 +00:00
refactor utility/storage.ts
This commit is contained in:
@@ -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のやつを解除
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user