Request persistent storage (#701)

* Request persistent storage

* Only prompt for persistent storage if push notifications enabled

---------

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
ekzyis 2023-12-20 21:38:43 +01:00 committed by GitHub
parent 9f7f09378d
commit 056be01f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -99,7 +99,15 @@ export const ServiceWorkerProvider = ({ children }) => {
if (pushSubscription) { if (pushSubscription) {
return unsubscribeFromPushNotifications(pushSubscription) return unsubscribeFromPushNotifications(pushSubscription)
} }
return subscribeToPushNotifications() return subscribeToPushNotifications().then(async () => {
// request persistent storage: https://web.dev/learn/pwa/offline-data#data_persistence
const persisted = await navigator?.storage?.persisted?.()
if (!persisted && navigator?.storage?.persist) {
return navigator.storage.persist().then(persistent => {
logger.info('persistent storage:', persistent)
}).catch(logger.error)
}
})
}) })
useEffect(() => { useEffect(() => {