fix(desktop): 关闭浏览器专有兜底(SW 注册 / Cache 虚拟路径 / 5MB 告警 / 自动快照)+ 隐藏与失焦时强制刷盘
This commit is contained in:
1 parent
f0ee2c1c61
commit
2b8bcbb74c
4 files changed
+29
-5
No files matched your search
+12
-1
@@ -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)
|
||||
@@ -438,7 +438,7 @@ function SettingsModal(props) {
|
||||
? ' 自动保存生成的图片到「默认下载文件夹」(设置 → 通用 → 下载;粘贴/插入的图片不保存)'
|
||||
: ' 自动保存生成的图片到本地(下载到浏览器下载目录,长久保存;粘贴/插入的图片不下载)')),
|
||||
el('div', { className: 'iwb-hint' }, isDesk()
|
||||
? '本地存储:' + fmtStorage(localStorageBytes()) + '(应用私有目录)。画布与图片分层存储——文本/引用存 localStorage,图片存 IndexedDB;建议定期用「备份与还原」导出 zip 到磁盘。'
|
||||
? '数据体积:' + fmtStorage(localStorageBytes()) + '(全部存于「资料目录」:data.json + images/)。图片是真实文件,画布里只留引用;备份用「备份与还原」导出 zip。'
|
||||
: '本地存储:' + fmtStorage(localStorageBytes()) + ' / 约 5MB。画布与图片分层存储——文本/引用存 localStorage,图片自动存 IndexedDB(容量大得多),写满会提示,不会静默丢失。'),
|
||||
el('div', { className: 'iwb-section-sub' }, '原图备份'),
|
||||
el('div', { className: 'iwb-row' },
|
||||
|
||||
@@ -150,6 +150,9 @@
|
||||
return r
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
// 桌面端(资料目录已生效)不做自动快照:数据本身就落盘了,再存一份 IndexedDB 快照是纯冗余
|
||||
// 调用方传 0 表示关闭;仍保留手动「立即备份」与列表读取。
|
||||
if (!(Number(delayMs) > 0)) return undefined
|
||||
let alive = true
|
||||
const t = setTimeout(async () => {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user