From 81a30f261ac099b968162579f1218ed091cdcfb0 Mon Sep 17 00:00:00 2001 From: qiqi Date: Fri, 27 Nov 2026 21:38:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(boot):=20=E4=BF=AE=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E7=99=BD=E5=B1=8F=E2=80=94=E2=80=94=E9=9D=99=E6=80=81=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=B1=8F=20+=20=E5=B9=B6=E8=A1=8C=E5=BB=BA=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=20+=20=E4=B8=80=E6=AC=A1=E6=80=A7=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E6=8C=AA=E5=88=B0=E9=A6=96=E5=B1=8F=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户把资料目录放局域网:点开后先有 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:同步新的阶段边界 --- docs/standards/architecture-current-state.md | 2 +- scripts/boot-splash.js | 73 ++++++++++++++++++++ scripts/build.js | 42 ++++++----- scripts/check-dist.js | 5 +- src/runtime-boot-progress.js | 6 +- src/storage-file.js | 44 ++++++++---- src/ui-splash.js | 2 + tests/boot-progress-test.js | 4 +- types/iwb-globals.d.ts | 1 + 9 files changed, 141 insertions(+), 38 deletions(-) create mode 100644 scripts/boot-splash.js diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index 6f87b2e..347a206 100644 --- a/docs/standards/architecture-current-state.md +++ b/docs/standards/architecture-current-state.md @@ -22,7 +22,7 @@ - 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob__`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。 - 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。 - 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。 -- `app.js` = 单 IIFE **8,323 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **26.2%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,174 行**(上限 **2,179**,余量 5;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **117** 个模块 / 23,462 行,`sourceModules` 117 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 +- `app.js` = 单 IIFE **8,323 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **26.2%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,174 行**(上限 **2,179**,余量 5;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **117** 个模块 / 23,482 行,`sourceModules` 117 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 - 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。 ## 2. 门禁与环境现状 diff --git a/scripts/boot-splash.js b/scripts/boot-splash.js new file mode 100644 index 0000000..6df7891 --- /dev/null +++ b/scripts/boot-splash.js @@ -0,0 +1,73 @@ +'use strict' +// 静态启动屏(v3.26.109):内联进 index.html,不依赖任何脚本就能出画面。 +// 为什么:资料目录放在局域网时,app.js 要等「存储装载」完成才渲染 React, +// 那段时间原本是纯白板(实测 15s)。 + +const css = `` + +const markup = `
+ +
生图工作台
+
+
正在启动…
+
` + +// 轮询进度总线:真实百分比(IWBBootProgress 就绪后),之前显示已等待秒数 +const script = `` + +module.exports = { css, markup, script } diff --git a/scripts/build.js b/scripts/build.js index ab771f6..f5eff78 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -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 = ` - - - - -无限画布 - - - - -
- - - - - -` +const bootSplash = require('./boot-splash') +const html = [ + '', + '', + '', + '', + '', + '无限画布', + '', + '', + // v3.26.109:静态加载屏内联在 index.html 里。资料目录在局域网时,app.js 要等存储装载完 + // 才渲染 React,那段时间原本是纯白板(实测 15s);这段 HTML/CSS 不依赖任何脚本就能出画面。 + bootSplash.css, + '', + '', + '
', + bootSplash.markup, + bootSplash.script, + '', + '', + '', + '', + '', + '' +].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;缺失不阻塞构建) diff --git a/scripts/check-dist.js b/scripts/check-dist.js index 17fa50f..3c23084 100644 --- a/scripts/check-dist.js +++ b/scripts/check-dist.js @@ -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(/