mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-08 01:06:41 +08:00
fix: PWA状态管理器初始化在DOM已加载时失败的问题
- 修复DOMContentLoaded事件监听器可能不触发的问题 - 检查document.readyState状态,如果DOM已就绪则立即初始化 - 确保PWA状态管理器在所有情况下都能正确初始化 - 解决main.ts作为模块加载时的时序问题
This commit is contained in:
+12
-3
@@ -96,8 +96,8 @@ app
|
|||||||
// 5. 初始化PWA状态管理器
|
// 5. 初始化PWA状态管理器
|
||||||
let pwaStateController: PWAStateController | null = null
|
let pwaStateController: PWAStateController | null = null
|
||||||
|
|
||||||
// 等待DOM准备就绪后初始化状态管理
|
// PWA状态管理器初始化函数
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
const initializePWAStateManager = () => {
|
||||||
// 检查是否在PWA模式下运行
|
// 检查是否在PWA模式下运行
|
||||||
const isPWA = window.matchMedia('(display-mode: standalone)').matches ||
|
const isPWA = window.matchMedia('(display-mode: standalone)').matches ||
|
||||||
(window.navigator as any).standalone ||
|
(window.navigator as any).standalone ||
|
||||||
@@ -129,7 +129,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
} else {
|
} else {
|
||||||
console.log('非PWA模式,跳过状态管理器初始化')
|
console.log('非PWA模式,跳过状态管理器初始化')
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// 检查DOM状态并初始化PWA状态管理
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
// DOM尚未加载完成,添加事件监听器
|
||||||
|
document.addEventListener('DOMContentLoaded', initializePWAStateManager)
|
||||||
|
} else {
|
||||||
|
// DOM已经准备就绪,立即初始化
|
||||||
|
initializePWAStateManager()
|
||||||
|
}
|
||||||
|
|
||||||
// 导出状态管理器供其他模块使用
|
// 导出状态管理器供其他模块使用
|
||||||
export { pwaStateController }
|
export { pwaStateController }
|
||||||
|
|||||||
Reference in New Issue
Block a user