mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-25 02:36:21 +03:00
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' {
|
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 {
|
interface PageLifecycleEvent extends Event {
|
||||||
newState: PageLifecycleState
|
newState: PageLifecycleState
|
||||||
|
|
|
@ -5,12 +5,22 @@ import { closeDatabases } from '~/utils/elk-idb'
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin(() => {
|
||||||
const state = ref(lifecycle.state)
|
const state = ref(lifecycle.state)
|
||||||
const frozenListeners: (() => void)[] = []
|
const frozenListeners: (() => void)[] = []
|
||||||
|
const frozenState = useLocalStorage(ELK_PAGE_LIFECYCLE_FROZEN, false)
|
||||||
|
|
||||||
lifecycle.addEventListener('statechange', (evt) => {
|
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())
|
frozenListeners.forEach(listener => listener())
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
state.value = evt.newState
|
state.value = evt.newState
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const addFrozenListener = (listener: () => void) => {
|
const addFrozenListener = (listener: () => void) => {
|
||||||
|
|
Loading…
Reference in a new issue