forked from Mirrors/elk
fix: handle frozen state (#1792)
This commit is contained in:
parent
d810b2de3a
commit
3596d8bec3
2 changed files with 13 additions and 3 deletions
2
page-lifecycle.d.ts
vendored
2
page-lifecycle.d.ts
vendored
|
@ -1,5 +1,5 @@
|
|||
declare module 'page-lifecycle/dist/lifecycle.mjs' {
|
||||
type PageLifecycleState = 'pageshow' | 'resume' | 'focus' | 'blur' | 'pagehide' | 'unload' | 'visibilitychange' | 'freeze'
|
||||
type PageLifecycleState = 'active' | 'passive' | 'hidden' | 'frozen' | 'terminated'
|
||||
|
||||
interface PageLifecycleEvent extends Event {
|
||||
newState: PageLifecycleState
|
||||
|
|
|
@ -5,12 +5,22 @@ import { closeDatabases } from '~/utils/elk-idb'
|
|||
export default defineNuxtPlugin(() => {
|
||||
const state = ref(lifecycle.state)
|
||||
const frozenListeners: (() => void)[] = []
|
||||
const frozenState = useLocalStorage(ELK_PAGE_LIFECYCLE_FROZEN, false)
|
||||
|
||||
lifecycle.addEventListener('statechange', (evt) => {
|
||||
if (evt.newState === 'freeze')
|
||||
if (evt.newState === 'hidden' && evt.oldState === 'frozen') {
|
||||
frozenState.value = false
|
||||
nextTick().then(() => window.location.reload())
|
||||
return
|
||||
}
|
||||
|
||||
if (evt.newState === 'frozen') {
|
||||
frozenState.value = true
|
||||
frozenListeners.forEach(listener => listener())
|
||||
else
|
||||
}
|
||||
else {
|
||||
state.value = evt.newState
|
||||
}
|
||||
})
|
||||
|
||||
const addFrozenListener = (listener: () => void) => {
|
||||
|
|
Loading…
Reference in a new issue