blob: 42743f78ea0e42371f4469c38c3e4619bd5a7d0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { readonly, ref } from 'vue';
import * as os from '@/os.js';
import { store } from '@/store.js';
import { i18n } from '@/i18n.js';
export const storagePersistenceSupported = window.isSecureContext && 'storage' in navigator;
const storagePersisted = ref(false);
export async function getStoragePersistenceStatusRef() {
if (storagePersistenceSupported) {
storagePersisted.value = await navigator.storage.persisted().catch(() => false);
}
return readonly(storagePersisted);
}
export async function enableStoragePersistence() {
if (!storagePersistenceSupported) return;
try {
const persisted = await navigator.storage.persist();
if (persisted) {
storagePersisted.value = true;
} else {
os.alert({
type: 'error',
text: i18n.ts.somethingHappened,
});
}
} catch (err) {
os.alert({
type: 'error',
text: i18n.ts.somethingHappened,
});
}
}
export function skipStoragePersistence() {
store.set('showStoragePersistenceSuggestion', false);
}
|