fix(desktop): 关闭浏览器专有兜底(SW 注册 / Cache 虚拟路径 / 5MB 告警 / 自动快照)+ 隐藏与失焦时强制刷盘

This commit is contained in:
qiqi committed 2026-11-17 06:38:27 +08:00
1 parent f0ee2c1c61
commit 2b8bcbb74c
4 files changed
+29 -5

No files matched your search

+12 -1
View File
@@ -377,5 +377,16 @@
__internals: { snapshot, loadInto, sha16, extOf, dataUrlToBytes, bytesToDataUrl },
}
// 关窗/收托盘前强制刷盘(beforeunload 在桌面端不保证,但能救一次是一次)
try { global.addEventListener('beforeunload', () => { try { flush() } catch (e) { /* ignore */ } }) } catch (e) { /* ignore */ }
// 落盘兜底:桌面端点关闭是「收进托盘」,beforeunload 不一定触发;
// 窗口被隐藏/失焦时也刷一次,避免最后 800ms 的改动只存在内存里。
try {
global.addEventListener('beforeunload', () => { try { flush() } catch (e) { /* ignore */ } })
global.addEventListener('pagehide', () => { try { flush() } catch (e) { /* ignore */ } })
if (global.document && global.document.addEventListener) {
global.document.addEventListener('visibilitychange', () => {
try { if (global.document.visibilityState === 'hidden') flush() } catch (e) { /* ignore */ }
})
}
if (global.addEventListener) global.addEventListener('blur', () => { try { flush() } catch (e) { /* ignore */ } })
} catch (e) { /* ignore */ }
})(typeof window !== 'undefined' ? window : globalThis)