Optimize PWA background performance with SSE and timer management

Co-authored-by: jxxghp <jxxghp@163.com>
This commit is contained in:
Cursor Agent
2025-07-06 14:52:58 +00:00
parent df76b01826
commit bea6c1e326
16 changed files with 1206 additions and 985 deletions

View File

@@ -594,12 +594,22 @@ export class PWAStateController {
}
private setupPeriodicSave(): void {
// 每30秒保存一次状态
setInterval(() => {
if (!document.hidden) {
this.saveCurrentState()
}
}, 30000)
// 导入后台管理器
import('@/utils/backgroundManager').then(({ addBackgroundTimer }) => {
// 使用后台管理器,延长间隔
addBackgroundTimer(
'pwa-state-save',
() => {
// 只在前台时保存状态(由后台管理器自动处理)
this.saveCurrentState()
},
60000, // 改为60秒减少频率
{
runInBackground: false, // 后台时不保存
skipInitialRun: true
}
)
})
}
private getAppSpecificState(): any {