fix: handle frozen page lifecycle state (#1658)

This commit is contained in:
Joaquín Sánchez 2023-02-06 23:22:56 +01:00 committed by GitHub
parent f7a8d471a6
commit 32cfe6371f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 134 additions and 3 deletions

View file

@ -1,4 +1,4 @@
import { get } from 'idb-keyval'
import { closeDatabases, get } from '../utils/elk-idb'
import type { MastoNotification, NotificationInfo, PushPayload, UserLogin } from './types'
export const findNotification = async (
@ -104,3 +104,7 @@ function htmlToPlainText(html: string) {
return decodeURIComponent(html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, ''))
}
*/
export function closeDatabaseConnections() {
closeDatabases()
}

View file

@ -1,10 +1,20 @@
/// <reference lib="WebWorker" />
/// <reference types="vite/client" />
import { createNotificationOptions, findNotification } from './notification'
import { ELK_PAGE_LIFECYCLE_FROZEN } from '../constants'
import {
closeDatabaseConnections,
createNotificationOptions,
findNotification,
} from './notification'
import type { PushPayload } from '~/service-worker/types'
declare const self: ServiceWorkerGlobalScope
self.addEventListener('message', (event) => {
if (event.data === ELK_PAGE_LIFECYCLE_FROZEN)
closeDatabaseConnections()
})
export const onPush = (event: PushEvent) => {
const promise = isClientFocused().then((isFocused) => {
if (isFocused)