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 { prefer } from '@/preferences.js';
|
||||||
import { $i } from '@/i.js';
|
import { $i } from '@/i.js';
|
||||||
import { launchPlugins } from '@/plugin.js';
|
import { launchPlugins } from '@/plugin.js';
|
||||||
import { initializeStoragePersistence } from '@/utility/storage.js';
|
|
||||||
|
|
||||||
export async function common(createVue: () => Promise<App<Element>>) {
|
export async function common(createVue: () => Promise<App<Element>>) {
|
||||||
console.info(`Misskey v${version}`);
|
console.info(`Misskey v${version}`);
|
||||||
@@ -328,10 +327,6 @@ export async function common(createVue: () => Promise<App<Element>>) {
|
|||||||
console.error('Failed to launch plugins:', error);
|
console.error('Failed to launch plugins:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ブラウザストレージ永続化の状態を初期化
|
|
||||||
// (top-level awaitを防ぐために明示的に起動時に確認する)
|
|
||||||
initializeStoragePersistence();
|
|
||||||
|
|
||||||
app.mount(rootEl);
|
app.mount(rootEl);
|
||||||
|
|
||||||
// boot.jsのやつを解除
|
// boot.jsのやつを解除
|
||||||
|
|||||||
@@ -51,10 +51,12 @@ import { enableAutoBackup, getPreferencesProfileMenu } from '@/preferences/utili
|
|||||||
import { store } from '@/store.js';
|
import { store } from '@/store.js';
|
||||||
import { signout } from '@/signout.js';
|
import { signout } from '@/signout.js';
|
||||||
import { genSearchIndexes } from '@/utility/inapp-search.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 searchIndex = await import('search-index:settings').then(({ searchIndexes }) => genSearchIndexes(searchIndexes));
|
||||||
|
|
||||||
|
const storagePersisted = await getStoragePersistenceStatusRef();
|
||||||
|
|
||||||
const indexInfo = {
|
const indexInfo = {
|
||||||
title: i18n.ts.settings,
|
title: i18n.ts.settings,
|
||||||
icon: 'ti ti-settings',
|
icon: 'ti ti-settings',
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ import MkKeyValue from '@/components/MkKeyValue.vue';
|
|||||||
import MkButton from '@/components/MkButton.vue';
|
import MkButton from '@/components/MkButton.vue';
|
||||||
import FormSlot from '@/components/form/slot.vue';
|
import FormSlot from '@/components/form/slot.vue';
|
||||||
import * as os from '@/os.js';
|
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 { ensureSignin } from '@/i.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import { definePage } from '@/page.js';
|
import { definePage } from '@/page.js';
|
||||||
@@ -180,6 +180,8 @@ import { cloudBackup } from '@/preferences/utility.js';
|
|||||||
|
|
||||||
const $i = ensureSignin();
|
const $i = ensureSignin();
|
||||||
|
|
||||||
|
const storagePersisted = await getStoragePersistenceStatusRef();
|
||||||
|
|
||||||
const reportError = prefer.model('reportError');
|
const reportError = prefer.model('reportError');
|
||||||
const enableCondensedLine = prefer.model('enableCondensedLine');
|
const enableCondensedLine = prefer.model('enableCondensedLine');
|
||||||
const skipNoteRender = prefer.model('skipNoteRender');
|
const skipNoteRender = prefer.model('skipNoteRender');
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ import { store } from '@/store.js';
|
|||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
|
|
||||||
export const storagePersistenceSupported = window.isSecureContext && 'storage' in navigator;
|
export const storagePersistenceSupported = window.isSecureContext && 'storage' in navigator;
|
||||||
const _storagePersisted = ref(false);
|
const storagePersisted = ref(false);
|
||||||
export const storagePersisted = readonly(_storagePersisted);
|
|
||||||
|
|
||||||
export async function initializeStoragePersistence() {
|
export async function getStoragePersistenceStatusRef() {
|
||||||
if (storagePersistenceSupported) {
|
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() {
|
export async function enableStoragePersistence() {
|
||||||
@@ -23,7 +24,7 @@ export async function enableStoragePersistence() {
|
|||||||
try {
|
try {
|
||||||
const persisted = await navigator.storage.persist();
|
const persisted = await navigator.storage.persist();
|
||||||
if (persisted) {
|
if (persisted) {
|
||||||
_storagePersisted.value = true;
|
storagePersisted.value = true;
|
||||||
} else {
|
} else {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
|
|||||||
Reference in New Issue
Block a user