Files
dsh-worktable/PATCH.md
T

48 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 本地补丁:工作台状态镜像到宿主侧
基于上游 `Aisland-SJL/dsh-worktable` **v0.5.1**,本地版本号改成 `0.5.2-local.1`。
## 为什么打这个补丁
桌面端宿主启动参数写死 `--port 0`(`@deepseek-ai/dsh-slark-desktop-host` 的
`windows-startup.js`:`--profile web --no-open --host 127.0.0.1 --port 0`),每次启动端口随机。
而工作台把项目/布局/绑定存在 localStorage(`dsh.worktable.projects.v1`、`dsh.worktable.view.v1`),
媒体存 IndexedDB —— 浏览器按「来源」隔离存储,端口一变就是另一个空库。
现象:新建的工作台,重启后消失。
## 改了什么
1. `01_content/src/index.ts`:新增路由 `GET/POST /api/worktable/state`
- 文件位置:`<DSH_HOME>/worktable-state.json`(走)`resolveDshHomeSafe()`)
- GET 读回,POST 原子写入(先写 `.tmp-<pid>-<ts>` 再 rename)
- 走宿主既有鉴权(`requestRejection`),和 `/api/worktable/file` 等私有路由一致
2. `01_content/src/client/hostState.ts`(新增):宿主镜像的读/写与 400ms 防抖合并
3. `01_content/src/client/index.tsx`:
- `loadView` / `loadProjects` 抽出 `normalizeView` / `normalizeProjects`,本地存档与宿主镜像共用校验
- `persistView` / `persistProjects` 额外写 `dsh.worktable.savedAt.v1` 并把状态排进宿主镜像
- 挂载时拉宿主镜像,只有 `updatedAt > 本地 savedAt` 才回填,避免旧镜像盖掉刚改的内容
- `markHydrated()` 之前的写入一律不发,防止首屏默认值把镜像冲掉
- `pagehide` / `beforeunload` 立即冲刷
## 覆盖范围
- 覆盖:项目、布局、绑定、文件夹、视图/外观设置
- **不覆盖**:图库媒体(照片)仍在 IndexedDB,换端口照样丢
## 构建 / 安装
```powershell
cd 01_content
npm install
npm run build # lib/index.js + lib/client.js
npm pack # 产出 dsh-worktable-0.5.2-local.1.tgz(7 文件,无 .map)
dsh plugin --profile web add "file:./dsh-plugins/dsh-worktable-0.5.2-local.1.tgz"
```
装完必须**完全退出宿主再重开**。
## 升级官方版时的注意
上游出 0.5.2 及以上时,本地补丁会被覆盖,需要把上面的三处改动重新合并到新版本再打包。
如果上游自己解决了「桌面端随机端口 + localStorage」,这个补丁就可以直接丢掉。