feat(boot): 修启动白屏——静态启动屏 + 并行建目录 + 一次性维护挪到首屏后
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m24s

用户把资料目录放局域网:点开后先有 15s 纯白板,然后进度条 1s 闪过。
原因有两层:
1) app.js 顶部 `await IWBStorageFile.ready()` 在 React 首次渲染之前,存储装载多久白板就多久;
   而 index.html 里没有任何静态画面,WebView 只能显示空白。
2) 那段装载里有一串串行网络往返:串行建 9 个子目录、读 data.json、逐个读画布、
   再加 5 个一次性维护(migrateBlobs/backfillGalleryThumbs/stripInlineGalleryThumbs/
   rotateTrash/dropLegacyDisplayThumbs),局域网下每次往返几百毫秒就是十几秒。

- scripts/boot-splash.js(新增)+ scripts/build.js:index.html 内联静态启动屏
  (logo/标题/进度条/阶段文字/已等待秒数),不依赖脚本即可出画面;React 启动屏挂载时顶掉它
- src/storage-file.js:ensureDirs 改并发(9 次往返 → 1 次);一次性维护延后到首屏后 1.2s;
  prepare 阶段按 4 步上报(授权 / 建目录 / 整理文件名 / 完成)
- src/runtime-boot-progress.js:阶段权重改为 prepare 0-10 / data 10-16 / canvases 16-70 /
  library 70-80 / finalize 80-96,进度条从第一秒起覆盖整段装载
- scripts/check-dist.js:index.html script 数 3→4(含内联启动屏),并断言启动屏存在
- tests/boot-progress-test.js:同步新的阶段边界
This commit is contained in:
qiqi committed 2026-11-27 21:38:05 +08:00
1 parent e3c7a3ff9b
commit 81a30f261a
9 files changed
+141 -38

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
'use strict'
// 静态启动屏(v3.26.109):内联进 index.html,不依赖任何脚本就能出画面。
// 为什么:资料目录放在局域网时,app.js 要等「存储装载」完成才渲染 React,
// 那段时间原本是纯白板(实测 15s)。
const css = `<style>
#iwb-boot-static{position:fixed;inset:0;z-index:2147483000;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;background:#f6f6f7;color:#1c1d1f;font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;transition:opacity .45s ease}
#iwb-boot-static.iwb-boot-out{opacity:0;pointer-events:none}
#iwb-boot-static .bs-logo{width:54px;height:54px;color:#575d69;animation:bs-bob 1.2s ease-in-out infinite}
#iwb-boot-static .bs-title{font-size:18px;font-weight:700;letter-spacing:1px}
#iwb-boot-static .bs-bar{width:300px;height:6px;border-radius:999px;background:#e8e9ec;border:1px solid #d8dade;overflow:hidden;position:relative}
#iwb-boot-static .bs-fill{position:absolute;left:0;top:0;bottom:0;width:8%;border-radius:999px;background:linear-gradient(90deg,#6b7280,#575d69);transition:width .32s cubic-bezier(.2,.7,.3,1)}
#iwb-boot-static .bs-fill::after{content:"";position:absolute;inset:0;transform:translateX(-100%);background:linear-gradient(90deg,transparent,#fff,transparent);animation:bs-sheen 1.5s ease-in-out infinite}
#iwb-boot-static .bs-meta{width:300px;display:flex;align-items:baseline;justify-content:space-between;gap:12px;font-size:12px;color:#5c6068}
#iwb-boot-static .bs-pct{font-variant-numeric:tabular-nums;font-weight:600;color:#1c1d1f}
@keyframes bs-bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-9px)}}
@keyframes bs-sheen{0%{transform:translateX(-100%)}100%{transform:translateX(100%)}}
@media (prefers-color-scheme:dark){
#iwb-boot-static{background:#161a19;color:#e9eaea}
#iwb-boot-static .bs-logo{color:#c9cbcd}
#iwb-boot-static .bs-bar{background:#23282a;border-color:#2f3638}
#iwb-boot-static .bs-fill{background:linear-gradient(90deg,#e8e8e8,#c9cbcd)}
#iwb-boot-static .bs-meta{color:#a8adb0}
#iwb-boot-static .bs-pct{color:#e9eaea}
}
@media (prefers-reduced-motion:reduce){#iwb-boot-static .bs-logo,#iwb-boot-static .bs-fill::after{animation:none}}
</style>`
const markup = `<div id="iwb-boot-static" role="status" aria-live="polite">
<svg class="bs-logo" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><circle cx="17.5" cy="17.5" r="3.5"/></svg>
<div class="bs-title">生图工作台</div>
<div class="bs-bar"><div class="bs-fill" id="bs-fill"></div></div>
<div class="bs-meta"><span id="bs-sub">正在启动…</span><span class="bs-pct" id="bs-pct"></span></div>
</div>`
// 轮询进度总线:真实百分比(IWBBootProgress 就绪后),之前显示已等待秒数
const script = `<script>
(function () {
var t0 = Date.now()
var box = document.getElementById('iwb-boot-static')
var fill = document.getElementById('bs-fill')
var sub = document.getElementById('bs-sub')
var pct = document.getElementById('bs-pct')
var lastPct = -1
function hide () {
if (!box) return
box.className = 'iwb-boot-out'
setTimeout(function () { if (box && box.parentNode) box.parentNode.removeChild(box) }, 500)
}
window.__iwbHideBootStatic = hide
function apply () {
if (!box) return
var bp = window.IWBBootProgress
var s = bp && bp.snapshot ? bp.snapshot() : null
if (s) {
if (!s.indeterminate && s.pct !== lastPct) {
lastPct = s.pct
fill.style.width = Math.max(8, s.pct) + '%'
pct.textContent = s.pct + '%'
}
sub.textContent = s.detail ? (s.label + ' · ' + s.detail) : s.label
if (s.done) { hide(); return }
} else {
var sec = Math.floor((Date.now() - t0) / 1000)
sub.textContent = '正在启动…' + (sec >= 2 ? ' ' + sec + 's' : '')
}
requestAnimationFrame(apply)
}
requestAnimationFrame(apply)
})()
</script>`
module.exports = { css, markup, script }
+25 -17
View File
@@ -230,23 +230,31 @@ const swWithVersion = swSource.replace(/__IWB_VERSION__/, version)
if (swWithVersion === swSource) throw new Error('__IWB_VERSION__ marker not found in sw.js')
fs.writeFileSync(path.join(dist, 'sw.js'), swWithVersion)
const html = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>无限画布</title>
<meta name="theme-color" content="#2563eb">
<link rel="stylesheet" href="style.css?v=${version}">
</head>
<body>
<div id="root"></div>
<script src="vendor/react.production.min.js"></script>
<script src="vendor/react-dom.production.min.js"></script>
<script src="app.js?v=${version}"></script>
</body>
</html>
`
const bootSplash = require('./boot-splash')
const html = [
'<!DOCTYPE html>',
'<html lang="zh-CN">',
'<head>',
'<meta charset="utf-8">',
'<meta name="viewport" content="width=device-width, initial-scale=1">',
'<title>无限画布</title>',
'<meta name="theme-color" content="#2563eb">',
'<link rel="stylesheet" href="style.css?v=' + version + '">',
// v3.26.109:静态加载屏内联在 index.html 里。资料目录在局域网时,app.js 要等存储装载完
// 才渲染 React,那段时间原本是纯白板(实测 15s);这段 HTML/CSS 不依赖任何脚本就能出画面。
bootSplash.css,
'</head>',
'<body>',
'<div id="root"></div>',
bootSplash.markup,
bootSplash.script,
'<script src="vendor/react.production.min.js"></script>',
'<script src="vendor/react-dom.production.min.js"></script>',
'<script src="app.js?v=' + version + '"></script>',
'</body>',
'</html>',
''
].join('\n')
fs.writeFileSync(path.join(dist, 'index.html'), html)
fs.writeFileSync(path.join(dist, 'version.json'), JSON.stringify({ version, packageVersion: pkg.version, commit: gitSha }, null, 2) + '\n')
// 导航 logo 用真实应用图标(v3.25.61;缺失不阻塞构建)
+3 -2
View File
@@ -41,9 +41,10 @@ if (!fs.existsSync(htmlPath)) fail('dist/index.html 不存在')
const html = fs.readFileSync(htmlPath, 'utf8')
if (!html.includes('app.js?v=')) fail('dist/index.html 缺少 app.js?v=')
const scriptCount = (html.match(/<script/g) || []).length
if (scriptCount !== 3) fail('dist/index.html <script 数量应为 3,实际 ' + scriptCount)
if (scriptCount !== 4) fail('dist/index.html <script 数量应为 4(React/ReactDOM/app.js + 内联启动屏),实际 ' + scriptCount)
if (!html.includes('iwb-boot-static')) fail('dist/index.html 缺少静态启动屏(局域网资料目录启动时的白屏兜底)')
if (html.includes('src/')) fail('dist/index.html 仍含 src/ 引用')
pass('dist/index.html 含 app.js?v=,<script 数量为 3,无 src/ 引用')
pass('dist/index.html 含 app.js?v=、静态启动屏,<script 数量为 4,无 src/ 引用')
// 3. dist/app.js 含无引号标记子串,证明内联压缩 worker 字面量在 minify 后仍存活
if (!app.includes('self.onmessage=async function(ev)')) {