From 95f010c6c47b80eb4f8f74c6a85effd88861ce57 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 15 Nov 2026 22:53:52 +0800 Subject: [PATCH 01/10] =?UTF-8?q?docs(agents):=20=E6=8F=90=E8=AE=AE?= =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E7=AB=AF=E6=9B=B4=E6=96=B0=E6=B8=A0=E9=81=93?= =?UTF-8?q?=E3=80=81=E5=8F=AF=E9=85=8D=E7=BD=AE=E6=9B=B4=E6=96=B0=E6=BA=90?= =?UTF-8?q?=E4=B8=8E=E5=85=88=E7=9C=8B=E6=97=A5=E5=BF=97=E7=9A=84=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=AF=B9=E8=AF=9D=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 记录正式版 / AutoBuild 双渠道、默认指向官方仓库且可改的签名更新源、 Motty 同款标题栏绿色下载箭头与“先显示更新日志再选择下载/跳过/稍后”的 更新对话框、不保留 Dev 身份的共用设置(保留不认识的配置并提示、切换渠道 可恢复设置快照),以及 Viva fork、store、桌面端和发布流水线的落地顺序。 Refs #1913 --- ...1-15-desktop-update-channels-and-dialog.md | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 .agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md diff --git a/.agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md b/.agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md new file mode 100644 index 0000000000..e80251e301 --- /dev/null +++ b/.agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md @@ -0,0 +1,203 @@ +# Agent 笔记:桌面端更新渠道、可配置更新源与更新对话框 + +状态:提议中 + +## 先说结论 + +Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发行构建带上更新源,设置页永远显示“此构建未配置更新源”。本方案把更新分成两个渠道:正式版(Stable,经过发布流程的版本)和 AutoBuild(每天从 `main` 自动构建)。两个渠道各有一份签名更新源,默认指向官方仓库 `1lck/Lithe-IDEA`,用户可以改成镜像地址。 + +更新的交互照 Motty: +- 有新版本时,标题栏右上角出现绿色下载箭头。 +- 点开后先显示这次更新了什么(更新日志),再由用户选择“下载并安装 / 跳过此版本 / 稍后”。 +- 检查到新版本后不在后台自动下载。 + +不再保留单独的 Dev 应用身份,两个渠道共用一份设置。旧版本读到不认识的配置时会忽略,但不会把它从文件里删掉,并提示用户。 + +## 问题 + +1. **更新不可用。** 发行构建没有注入 `UpdateFeedURL`、`UpdatePublicKeys` 和 `UpdateChannel`(见 `desktop/internal/buildinfo/update.go`)。所以 `newUpdateClient` 返回 nil,设置页只显示“未配置”。用户每次都要去发布页手动下载完整安装包,增量更新的客户端代码也一直用不上([#1913](https://github.com/1lck/Lithe-IDEA/issues/1913))。 +2. **只有一个渠道。** `UpdateChannel` 只是一个字符串。用户不能在“稳定”和“每天最新”之间选择,AutoBuild 用户也无法回到正式版。 +3. **跨渠道比较版本号会装错版本。** AutoBuild 版本号沿用 `viva.toml` 的 `0.7.0`。按语义化版本(SemVer),`0.7.0-autobuild.<时间>` 小于正式版 `0.7.0`。如果直接比较,AutoBuild 用户会被“更新”回更旧的正式版代码。 +4. **更新提示没有内容。** + - Viva 的签名更新源(feed)只有 `notes_url` 链接,没有日志正文。用户看不到更新了什么就要决定下载。 + - 后台检查发现新版本时,只弹一条“有新版本”的通知,没有统一的入口。 +5. **旧版本会抹掉新版本的设置。** `desktop/internal/store/store.go` 保存时把 Go 结构体整个序列化写回文件。旧版本不认识的字段读的时候被丢掉,下一次保存时就从文件里消失了。 + - 两个渠道共用设置以后,在 AutoBuild 和正式版之间切换,很容易触发这个问题。 + - 这是现有缺陷,与渠道无关也应修复。 + +## 提案 + +### 1. 两个渠道:“安装渠道”与“更新渠道”分开 + +- **安装渠道**由打包时写入,用户不能修改,表示“现在装的是什么”。 + - `buildinfo` 增加渠道、构建时间(UTC)和 commit,由打包脚本通过 `-X` 注入。 + - 带 `lithe_stable` 标签的构建是正式版,AutoBuild 工作流打出来的是 AutoBuild。 + - 本地 `go build` 和带 `dev` 标签的构建是“本地构建”:不检查更新,渠道选项置灰。 +- **更新渠道**由用户在设置里选择,表示“以后从哪个渠道更新”。默认跟随安装渠道。存进 `settings.json` 的 `updateChannel`,空值表示跟随安装渠道。 +- **AutoBuild 版本号**改为 `-autobuild.`,例如 `0.7.0-autobuild.20261115100000`。 + - 同一渠道内照常按 SemVer 比较,时间越新越大。 +- **跨渠道从不比较完整版本号**,切换规则如下: + +| 情况 | 行为 | +| --- | --- | +| 更新渠道等于安装渠道 | 正常更新,可用增量补丁 | +| 正式版 → AutoBuild | 先确认风险,再显示 AutoBuild 的更新日志对话框;确认后完整下载并替换 | +| AutoBuild → 正式版 | 默认等下一个基础版本更高的正式版(`0.7.1` 高于 `0.7.0-autobuild.*` 的基础 `0.7.0`);同时提供“现在回到正式版”,完整安装最新正式版,并提示它可能比当前代码旧 | +| 下载或安装进行中 | 不允许切换渠道 | +| 切换完成 | 丢弃另一渠道已下载的包,立即检查新渠道 | + +- 跨渠道需要拿到“已验签、但不一定更新”的更新源。为此要在 Viva fork 增加 `Client.Latest(ctx)`:做与 `Client.Check` 相同的签名、模式、应用和渠道校验,但不做版本比较。 + +### 2. 更新源可配置,默认指向官方仓库 + +- 默认地址写在代码里,不再只依赖 `-X` 注入,这样任何构建都有默认源: + - `https://github.com/1lck/Lithe-IDEA/releases/download/desktop-update-feed/stable.json` + - `https://github.com/1lck/Lithe-IDEA/releases/download/desktop-update-feed/autobuild.json` + - fork 仓库可以在构建时用 `-X` 覆盖这个默认值。 +- 设置页每个渠道一行更新源。 + - 默认显示为“默认(github.com/1lck/Lithe-IDEA)”,可改成自定义 HTTPS 地址,也可以恢复默认。 + - 只有用户修改过的渠道才写入 `settings.json` 的 `updateSources`。 +- **自定义源只换下载地址,不换信任对象**:仍用内置公钥验签。镜像必须原样提供官方签名过的文件,不能自己生成更新源;需要自己密钥的 fork 必须自己编译。 +- 签名公钥保持逗号分隔的多把,用于轮换密钥:新旧两把公钥同时内置一段时间,再停用旧钥。 + +### 3. 更新流程:先看日志,再决定 + +1. 检查时机沿用现有的启动后 5 秒、之后每小时。发现更新的版本时: + - 标题栏最右侧(可排列按钮区之后、系统窗口按钮之前)出现绿色圆环加实心下箭头的按钮。 + - 图形和颜色沿用 Motty 的 `updateIcon`,颜色 `RGB(22, 163, 74)`,明暗主题相同。 + - 悬停提示写出版本号和点击后会发生什么。 + - 同一版本只弹一次通知,带“查看更新内容”按钮。 + - 不弹对话框,免得打断正在输入的人;也不自动下载。 +2. 点绿箭头、通知按钮或设置页“查看更新内容”,都打开**更新对话框**: + - 标题是版本号。 + - 副标题依次是当前版本、渠道、下载大小(有增量补丁时同时显示增量和完整大小)。 + - 正文是 Markdown 更新日志,限高可滚动,链接在浏览器打开;底部有“在 GitHub 查看完整说明”。 + - 按钮是“跳过此版本 / 稍后 / 下载并安装”。 + - 不能自更新时(deb/rpm 管理的安装返回 `ErrManagedExternally`,安装目录不可写返回 `ErrNotWritable`),主按钮换成“打开下载页面”,正文下方说明原因。 +3. **三个选择:** + - **跳过此版本**:按渠道记入 `updateSkipped`。绿箭头和通知不再为这个版本出现;更新的版本照常提示。用户主动“检查更新”时仍显示它。 + - **稍后**:关闭对话框,绿箭头保留。 + - **下载并安装**:开始下载。对话框可以关闭,此时绿箭头外圈变为进度环,再点可以查看进度或取消。 + - 应用补丁的阶段不能取消,沿用现有 `Applying` 语义。 +4. 下载并校验完成后,绿箭头变为“已就绪”样式,对话框主按钮变为“重启并更新”。补丁失败时改下完整包,沿用现有逻辑。 +5. 用户主动点“检查更新”且有新版本时,直接打开对话框,不受“跳过此版本”影响。没有新版本时,只在设置页显示“已是最新”。 + +### 4. 更新日志的来源 + +- Viva fork 的 `update.Release` 增加 `notes` 字段(Markdown,最多 16 KB),`viva feed` 增加读取日志文件的参数。日志在签名范围内,客户端不需要另外请求 GitHub API,不受未登录限流影响,镜像也能用。 +- **正式版**:使用 `desktop-vX.Y.Z` 发布说明的正文。 +- **AutoBuild**:工作流根据上一次 AutoBuild commit 到本次 commit 之间的 first-parent 提交(PR 标题和编号)生成。超长时截断,并附完整的 compare 链接。 + +### 5. 不保留 Dev 身份,共用设置 + +- 两个渠道使用同一个应用 ID `app.lithe.viva`、同一个设置目录和同一个安装位置;切换渠道就是原地替换安装包。 +- **保留不认识的配置**,在 `desktop/internal/store/` 统一实现,所有经 `store.Save` 保存的文件都受益: + - 读取时,按目标类型的 JSON 字段(包括嵌套对象)找出当前版本不认识的键。同名字段但格式变了、解码失败的,也按不认识处理:当前版本用默认值,原值保留。 + - 保存时,先写当前结构体,再把这些键原样合并回去。 + - 当前版本认识、但被用户清空的字段正常删除,不能被旧值“复活”。 +- **提示**:读取到不认识的配置时,每组键只通知一次:“有 N 项设置来自更新版本的 Lithe,当前版本不支持,已忽略但没有删除。”通知可展开查看键名。 +- **切换渠道时可以选择恢复设置:** + - 跨渠道安装前,把 `settings.json` 的原始字节存一份快照到用户数据目录的 `update-snapshots/<渠道>-<版本>-<时间>.json`,只保留最近 5 份。 + - 以后切回某个渠道时,确认对话框提供“保留当前设置(推荐)”和“恢复上次使用该渠道时的设置”。 + - 恢复时直接复制原始字节,不经过结构体,避免再次丢字段。 + - 快照只写用户数据目录,不写安装目录(见 [运行时只读边界](../../implemented/bug-fix/2026-09-25-runtime-bundle-immutability-and-update-delta.md))。 + +### 6. 发布端(#1913) + +- 用 `viva update-keygen` 生成 Ed25519 密钥。私钥存为 Actions secret `VIVA_UPDATE_KEY`,公钥编译进程序。私钥不进仓库。 +- 固定的滚动 tag `desktop-update-feed` 下放 `stable.json`、`autobuild.json` 和各自的 `.sig`。正式版和 AutoBuild 工作流只更新自己那一份。 + - 不能用 `releases/latest`,因为 `desktop-v*` 都以 prerelease 发布。 +- 安装包仍放在各自的版本 release 里,更新源里的地址指向它们。 +- AutoBuild 的增量补丁必须基于上一次 AutoBuild 的精确字节,所以要在滚动 release 被覆盖前下载上一版归档。 + +### 7. 落地顺序 + +1. **Lithe-IDEA/viva fork**: + - 加 `Client.Latest`、`Release.Notes` 和 `viva feed` 的日志参数,并按 fork 规则同时向上游提 PR。 + - 确认 macOS 安装器接受带预发布后缀的 `CFBundleShortVersionString`。 +2. **`desktop/internal/store`**:保留不认识的配置,加上提示。按缺陷修复流程,先写在修复前失败的回归测试。 +3. **桌面端更新:** + - 渠道与更新源设置。 + - 标题栏绿箭头、更新对话框、跳过和稍后、进度、重启更新。 + - 设置快照与恢复。 + - 中英文词条、Core 日志目录事件、功能矩阵和无头截图。 +4. **发布流水线(#1913)**:密钥、两份更新源、日志生成、构建注入、真实签名产物演练。 + +更新器继续留在 `desktop/` 的 Go 代码里。Viva 是 macOS、Windows 和 Linux 的唯一客户端;签名、比较和安装复用上游 Viva `update` 包,不在 Rust Core 另写一套。 + +### 正确做法 + +- AutoBuild 用户把更新渠道改成正式版、最新正式版是 `0.7.0` 时,提示“将在高于 0.7.0 的正式版发布时更新”,并提供“现在回到正式版”。 +- 后台检查发现 `0.7.1`:出现绿箭头和一次通知,用户点开后先看到日志,再决定下载。 +- 旧版本读到新版本写的 `editorPreferences.foo`:用默认行为运行,保存时把 `foo` 原样写回,并通知一次。 + +### 不要这样做 + +- 不要直接比较 `0.7.0` 和 `0.7.0-autobuild.20261115100000` 来决定跨渠道更新,SemVer 会认为正式版更新。 +- 不要让没人请求的检查弹出对话框,或者在后台自动下载。被跳过的版本白白消耗流量,用户也失去了先看内容的机会。 +- 不要让 `store.Save` 只写结构体里的字段,那样旧版本保存一次,新版本的设置就没了。 +- 不要从 GitHub Releases API 读日志:未登录有限流,内容不在签名范围内,镜像也没有这个 API。 +- 不要把设置快照写进 app bundle 或 Windows 安装目录。 + +## 考虑过的备选方案 + +### AutoBuild 使用单独的 Lithe-Dev 应用身份 + +已退役的 Swift 客户端曾让 AutoBuild 用独立的应用 ID。它最有吸引力的地方是两个版本的设置天然隔离,还能同时安装。 + +不采用的原因:用户要维护两个应用和两份设置,切换渠道时设置不跟着走。维护者已明确不保留 Dev 版本。设置冲突改由“保留不认识的配置”和快照恢复解决。 + +### 发现新版本就在后台下载,下载完再显示日志 + +这是 Sparkle 等更新器的常见做法,用户点“重启”就能立刻更新。 + +不采用的原因:用户还没看到更新内容就已经花掉了流量;被跳过的版本也会被下载。维护者明确要求先显示更新内容,再选择下载或跳过。 + +### 日志直接读 GitHub Release 正文 + +不需要修改 Viva 的更新源格式,正式版的发布说明也已经存在。 + +不采用的原因:未登录时每小时只有 60 次请求;正文不在签名范围内;自定义镜像拿不到;滚动的 AutoBuild release 正文也不对应具体版本。 + +### 每个渠道一份独立的设置文件 + +彻底避免新旧版本互相改写设置。 + +不采用的原因:用户在一个渠道里调好的设置,切到另一个渠道就没有了。维护者要求共用设置。 + +### 一份更新源同时包含两个渠道 + +只维护一个文件。 + +不采用的原因:Viva 的 `Feed` 一个文件只表示一个渠道,并校验 `Channel` 字段;而且正式版和 AutoBuild 由不同工作流、在不同时间发布,同时改写一个文件容易冲突。 + +## 验收标准 + +- 正式版构建和 AutoBuild 构建打开设置 → 更新,都能显示安装渠道、构建时间和 commit,并能检查更新,不再显示“未配置”。本地构建显示本地构建,不检查更新。 +- 后台检查发现新版本后,标题栏出现绿箭头,同一版本只通知一次,不弹对话框,不自动下载。 +- 对话框先显示签名更新源里的 Markdown 日志。“跳过此版本”之后,这个版本不再出现绿箭头和通知;更新的版本出现时照常提示。 +- 下载中绿箭头显示进度,可以取消;下载完成后可以重启更新。deb/rpm 和不可写的安装只提供下载页面,并说明原因。 +- 从正式版切到 AutoBuild,以及从 AutoBuild 回到正式版,都走完整安装,且不会因为版本比较装错版本。下载中不能切换渠道。 +- 自定义更新源能正常检查和下载;签名不匹配时拒绝并显示原因。恢复默认后回到官方源。 +- 旧版本读写含新字段的 `settings.json` 后,新字段原样保留,并提示一次;被清空的已知字段不会复活。 +- 切回某个渠道时可以选择恢复快照,恢复后的文件与快照字节一致。 +- 发布流水线为两个渠道生成签名的更新源,并经过真实签名产物演练:完整更新、增量更新、补丁不可用时回退完整包;`scripts/desktop/verify/verify-runtime-bundle-immutability.sh` 通过。 + +## 风险 + +- **macOS 版本字符串**:Viva 的 macOS 安装器要求包内 `CFBundleShortVersionString` 与更新源版本一致。如果打包或安装器不接受带预发布后缀的版本,需要在 fork 里改为比较基础版本加构建号,并同步上游。 +- **私钥丢失或泄露**:所有已安装的客户端都会停在旧版本。私钥必须备份;客户端支持多把公钥,可以轮换。 +- **fork 与上游分歧**:`Client.Latest` 和 `Release.Notes` 必须同时向上游提 PR。上游方案不同时以上游为准,按 fork 维护规则替换。 +- **合并设置的边界情况**:嵌套对象、数组和类型变化的字段容易出错,需要用回归测试覆盖“未知键保留”“已知键清空”“类型冲突”三种情况。出问题时可以回退到只保留顶层未知键。 +- **日志事件依赖 Core**:渠道切换、跳过版本、更新源失败、保留未知配置等新事件,要先在固定 Core 修订的日志目录里声明。Core PR 没合入之前,桌面端 PR 不能标记 ready。 +- **AutoBuild 增量补丁**:滚动 release 被覆盖后就拿不到上一版的精确字节。发布流程必须在覆盖前取得旧包;取不到时只发布完整包。 + +## 适用范围 + +- `desktop/internal/buildinfo/` +- `desktop/internal/workbench/updates.go` +- `desktop/internal/workbench/chrome_view.go` +- `desktop/internal/settingswindow/updates_view.go` +- `desktop/internal/store/` +- `scripts/ci/desktop-autobuild/` +- `scripts/desktop/package-desktop.sh` From f9f2e8f8ebd9246657cdb9983783f12d861b4c42 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 15 Nov 2026 23:10:57 +0800 Subject: [PATCH 02/10] docs(notes): follow Motty for update notes and delta patches Motty 0.4.10 uses the Viva update package with a signed feed and fetches the release notes separately after the check. Do the same: notes live beside each feed with a version header, so no Viva fork change and no Client.Latest are needed; cross-channel checks override Config.Current. Patches come from the previous build, as Motty's mirror-release.sh does. Refs #1913 --- ...1-15-desktop-update-channels-and-dialog.md | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/.agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md b/.agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md index e80251e301..379553cc6c 100644 --- a/.agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md +++ b/.agents/notes/proposed/feature/2026-11-15-desktop-update-channels-and-dialog.md @@ -46,7 +46,10 @@ Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发 | 下载或安装进行中 | 不允许切换渠道 | | 切换完成 | 丢弃另一渠道已下载的包,立即检查新渠道 | -- 跨渠道需要拿到“已验签、但不一定更新”的更新源。为此要在 Viva fork 增加 `Client.Latest(ctx)`:做与 `Client.Check` 相同的签名、模式、应用和渠道校验,但不做版本比较。 +- 跨渠道检查不需要改 Viva。`update.Config.Current` 是“和谁比较”,不必是正在运行的版本: + - 立即切换(正式版 → AutoBuild、“现在回到正式版”)时传 `0.0.0`,`Client.Check` 照常验签、校验模式、应用和渠道,返回目标渠道的最新版本。 + - AutoBuild 等下一个正式版时传基础版本(去掉预发布后缀,如 `0.7.0`),只有更高的正式版才算更新。 + - 跨渠道一律不用增量补丁:补丁只对同一渠道上一版的精确字节有效。 ### 2. 更新源可配置,默认指向官方仓库 @@ -82,9 +85,15 @@ Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发 4. 下载并校验完成后,绿箭头变为“已就绪”样式,对话框主按钮变为“重启并更新”。补丁失败时改下完整包,沿用现有逻辑。 5. 用户主动点“检查更新”且有新版本时,直接打开对话框,不受“跳过此版本”影响。没有新版本时,只在设置页显示“已是最新”。 -### 4. 更新日志的来源 +### 4. 更新日志的来源(照 Motty) -- Viva fork 的 `update.Release` 增加 `notes` 字段(Markdown,最多 16 KB),`viva feed` 增加读取日志文件的参数。日志在签名范围内,客户端不需要另外请求 GitHub API,不受未登录限流影响,镜像也能用。 +Motty 0.4.10 的做法:签名的 Viva 更新源只带版本、安装包和补丁;`Client.Check` 发现新版本后,再单独请求这个版本的说明,取不到就在对话框里显示“没有更新说明”。日志只是展示内容,信任仍然来自签名更新源里的安装包摘要,所以不需要把日志签进更新源,也不用改 Viva。 + +Lithe 照这个顺序做,只换日志的位置: + +- 日志放在更新源旁边:`stable.json` 旁是 `stable.notes.md`,`autobuild.json` 旁是 `autobuild.notes.md`,和更新源一起发布到 `desktop-update-feed`。镜像整目录复制即可,自定义更新源也能拿到日志。 +- 第一行是 ``。客户端只在版本与已验签的更新源一致时显示正文,避免更新源和日志先后上传时显示错版本的日志。 +- 客户端最多读 16 KB,按 UTF-8 字符边界截断,和 Motty 一样。 - **正式版**:使用 `desktop-vX.Y.Z` 发布说明的正文。 - **AutoBuild**:工作流根据上一次 AutoBuild commit 到本次 commit 之间的 first-parent 提交(PR 标题和编号)生成。超长时截断,并附完整的 compare 链接。 @@ -108,20 +117,24 @@ Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发 - 固定的滚动 tag `desktop-update-feed` 下放 `stable.json`、`autobuild.json` 和各自的 `.sig`。正式版和 AutoBuild 工作流只更新自己那一份。 - 不能用 `releases/latest`,因为 `desktop-v*` 都以 prerelease 发布。 - 安装包仍放在各自的版本 release 里,更新源里的地址指向它们。 -- AutoBuild 的增量补丁必须基于上一次 AutoBuild 的精确字节,所以要在滚动 release 被覆盖前下载上一版归档。 +- **增量补丁照 Motty 的 `tools/mirror-release.sh`**: + - 发布前下载上一版的归档,逐个平台传给 `viva feed -patch-from /=<上一版版本>=<旧归档>`。只为上一版生成补丁,更早的版本下载完整包。 + - 正式版的上一版是上一个 `desktop-v*`;AutoBuild 的上一版是 `desktop-AutoBuild` 当前持有的归档,必须在滚动 release 被覆盖前下载。 + - Windows 的补丁挂在 zip 上,NSIS 安装版复用同一个补丁(Motty 的 `patchesFor`)。macOS 只给 zip 生成补丁,dmg 不进更新源。 + - 取不到上一版时只发布完整包,不让发布失败。 +- `viva` 命令从 `desktop/go.mod` 的 `replace` 目录编译,不用 `go run …/cmd/viva@<版本>`(Motty 这样做,但会绕过 Lithe 的 fork 固定)。 ### 7. 落地顺序 -1. **Lithe-IDEA/viva fork**: - - 加 `Client.Latest`、`Release.Notes` 和 `viva feed` 的日志参数,并按 fork 规则同时向上游提 PR。 - - 确认 macOS 安装器接受带预发布后缀的 `CFBundleShortVersionString`。 -2. **`desktop/internal/store`**:保留不认识的配置,加上提示。按缺陷修复流程,先写在修复前失败的回归测试。 -3. **桌面端更新:** +维护者要求一次做完,下面几部分放在同一个 PR 里;不需要改 Viva fork。 + +1. **`desktop/internal/store`**:保留不认识的配置,加上提示。按缺陷修复流程,先写在修复前失败的回归测试。 +2. **桌面端更新:** - 渠道与更新源设置。 - 标题栏绿箭头、更新对话框、跳过和稍后、进度、重启更新。 - 设置快照与恢复。 - 中英文词条、Core 日志目录事件、功能矩阵和无头截图。 -4. **发布流水线(#1913)**:密钥、两份更新源、日志生成、构建注入、真实签名产物演练。 +3. **发布流水线(#1913)**:两份更新源和旁边的日志、增量补丁、构建注入。密钥由维护者生成后写入 secret;没有密钥时跳过更新源发布。 更新器继续留在 `desktop/` 的 Go 代码里。Viva 是 macOS、Windows 和 Linux 的唯一客户端;签名、比较和安装复用上游 Viva `update` 包,不在 Rust Core 另写一套。 @@ -136,7 +149,8 @@ Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发 - 不要直接比较 `0.7.0` 和 `0.7.0-autobuild.20261115100000` 来决定跨渠道更新,SemVer 会认为正式版更新。 - 不要让没人请求的检查弹出对话框,或者在后台自动下载。被跳过的版本白白消耗流量,用户也失去了先看内容的机会。 - 不要让 `store.Save` 只写结构体里的字段,那样旧版本保存一次,新版本的设置就没了。 -- 不要从 GitHub Releases API 读日志:未登录有限流,内容不在签名范围内,镜像也没有这个 API。 +- 不要先下载再给日志,也不要因为日志取不到就不提示更新:日志失败只影响正文,对话框照常显示版本、大小和按钮。 +- 不要从 GitHub Releases API 读日志:未登录每小时只有 60 次请求,镜像也没有这个 API,滚动的 AutoBuild release 正文是下载说明模板。 - 不要把设置快照写进 app bundle 或 Windows 安装目录。 ## 考虑过的备选方案 @@ -153,11 +167,17 @@ Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发 不采用的原因:用户还没看到更新内容就已经花掉了流量;被跳过的版本也会被下载。维护者明确要求先显示更新内容,再选择下载或跳过。 -### 日志直接读 GitHub Release 正文 +### 把日志签进更新源(给 Viva fork 加 `Release.Notes`) + +日志和安装包一起验签,客户端只需一次请求。 + +不采用的原因:要给 fork 加格式字段并向上游提 PR,桌面端 PR 要等 fork 合入才能固定版本。Motty 已经证明不签名的日志足够:日志只是展示内容,能不能安装由签名更新源里的摘要决定。 + +### 日志直接读 GitHub Release 正文(Motty 的来源) -不需要修改 Viva 的更新源格式,正式版的发布说明也已经存在。 +不需要额外发布文件,正式版的发布说明也已经存在。 -不采用的原因:未登录时每小时只有 60 次请求;正文不在签名范围内;自定义镜像拿不到;滚动的 AutoBuild release 正文也不对应具体版本。 +不采用的原因:未登录时每小时只有 60 次请求;自定义镜像拿不到;滚动的 AutoBuild release 正文是固定的下载说明,不是这次构建改了什么。Lithe 只沿用 Motty 的顺序(验签后再取日志、取不到就显示没有说明),日志改放在更新源旁边。 ### 每个渠道一份独立的设置文件 @@ -175,7 +195,7 @@ Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发 - 正式版构建和 AutoBuild 构建打开设置 → 更新,都能显示安装渠道、构建时间和 commit,并能检查更新,不再显示“未配置”。本地构建显示本地构建,不检查更新。 - 后台检查发现新版本后,标题栏出现绿箭头,同一版本只通知一次,不弹对话框,不自动下载。 -- 对话框先显示签名更新源里的 Markdown 日志。“跳过此版本”之后,这个版本不再出现绿箭头和通知;更新的版本出现时照常提示。 +- 对话框先显示更新源旁边、版本一致的 Markdown 日志;日志取不到或版本不一致时显示“没有更新说明”,其余照常。“跳过此版本”之后,这个版本不再出现绿箭头和通知;更新的版本出现时照常提示。 - 下载中绿箭头显示进度,可以取消;下载完成后可以重启更新。deb/rpm 和不可写的安装只提供下载页面,并说明原因。 - 从正式版切到 AutoBuild,以及从 AutoBuild 回到正式版,都走完整安装,且不会因为版本比较装错版本。下载中不能切换渠道。 - 自定义更新源能正常检查和下载;签名不匹配时拒绝并显示原因。恢复默认后回到官方源。 @@ -185,9 +205,8 @@ Viva 桌面端已经能检查、下载和安装签名更新,但没有任何发 ## 风险 -- **macOS 版本字符串**:Viva 的 macOS 安装器要求包内 `CFBundleShortVersionString` 与更新源版本一致。如果打包或安装器不接受带预发布后缀的版本,需要在 fork 里改为比较基础版本加构建号,并同步上游。 +- **macOS 版本字符串**:Viva 的 macOS 安装器只要求包内 `CFBundleShortVersionString` 与更新源版本字符串完全相同(`update/install_darwin.go`),打包时也把版本原样写进这个字段和 `CFBundleVersion`,所以 `0.7.0-autobuild.<时间>` 不需要改 Viva。仍要在发布演练中确认签名、公证和 Finder 都接受这个字符串。 - **私钥丢失或泄露**:所有已安装的客户端都会停在旧版本。私钥必须备份;客户端支持多把公钥,可以轮换。 -- **fork 与上游分歧**:`Client.Latest` 和 `Release.Notes` 必须同时向上游提 PR。上游方案不同时以上游为准,按 fork 维护规则替换。 - **合并设置的边界情况**:嵌套对象、数组和类型变化的字段容易出错,需要用回归测试覆盖“未知键保留”“已知键清空”“类型冲突”三种情况。出问题时可以回退到只保留顶层未知键。 - **日志事件依赖 Core**:渠道切换、跳过版本、更新源失败、保留未知配置等新事件,要先在固定 Core 修订的日志目录里声明。Core PR 没合入之前,桌面端 PR 不能标记 ready。 - **AutoBuild 增量补丁**:滚动 release 被覆盖后就拿不到上一版的精确字节。发布流程必须在覆盖前取得旧包;取不到时只发布完整包。 From 14c1fda9a94aa3b0d8fc54f17c705a4274cd0235 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 15 Nov 2026 23:27:42 +0800 Subject: [PATCH 03/10] =?UTF-8?q?fix(desktop):=20=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=97=B6=E4=BF=9D=E7=95=99=E6=AD=A4=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=8D=E8=AE=A4=E8=AF=86=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=B9=B6=E6=8F=90=E7=A4=BA=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 正式版和 AutoBuild 共用一个 settings.json。store.Save 以前按当前版本的 结构体重写整个文件,较新版本写入的字段、或形状变了的值,换到较旧版本 保存一次就丢了;值形状不对时 Load 还会整体失败、回落默认设置。 - store.Load 按目标类型遍历文件,记住没有字段读取的键和解码不了的值; Save 把它们合并回去。当前版本自己改过或清空的字段以当前值为准, 被删掉的对象不会带回里面的键。 - 首个窗口启动时,如有不认识的配置,提示一次(数量和前五个键名), 同一组键不再重复提示。提示在恢复背景之后再保存,不会清掉背景设置。 Refs #1913 --- desktop/internal/i18n/shared.generated.go | 2 + desktop/internal/store/keep.go | 305 ++++++++++++++++++ desktop/internal/store/keep_test.go | 191 +++++++++++ desktop/internal/store/store.go | 96 +++++- desktop/internal/workbench/app.go | 8 + desktop/internal/workbench/settings_kept.go | 55 ++++ .../internal/workbench/settings_kept_test.go | 55 ++++ shared/i18n/locales/en-US.json | 1 + shared/i18n/locales/zh-CN.json | 1 + shared/i18n/messages.json | 11 + 10 files changed, 720 insertions(+), 5 deletions(-) create mode 100644 desktop/internal/store/keep.go create mode 100644 desktop/internal/store/keep_test.go create mode 100644 desktop/internal/workbench/settings_kept.go create mode 100644 desktop/internal/workbench/settings_kept_test.go diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index c3f88d900d..2d21c70096 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1444,6 +1444,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.terminal.scrollbackMore": "More lines", "desktop.settings.terminalShellHelp": "The shell a new terminal runs, including the one the Terminal tool window opens by itself. The ⌄ menu beside + opens a terminal in another installed shell.", "desktop.settings.terminalShellMissing": "{path} (not found)", + "desktop.settings.unknownKept": "The settings file has {count} settings this version does not recognize ({keys}). This version ignores them but keeps them, so they still apply when you switch back to a version that knows them.", "desktop.settings.updates.applying": "Building Lithe {version} from the delta update…", "desktop.settings.updates.auto": "Check for updates automatically", "desktop.settings.updates.autoHelp": "Checks 5 seconds after launch, then every hour. Checks pause while the window is in the background and catch up when it returns. The update server sees your IP address when Lithe checks.", @@ -4058,6 +4059,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.terminal.scrollbackMore": "增加行数", "desktop.settings.terminalShellHelp": "新建终端时运行的 Shell,也包括终端工具窗口自动打开的那个。+ 旁边的 ⌄ 菜单可以用其他已安装的 Shell 新建终端。", "desktop.settings.terminalShellMissing": "{path}(未找到)", + "desktop.settings.unknownKept": "设置文件中有 {count} 项此版本无法识别的设置({keys})。此版本不会使用它们,但会原样保留,换回能识别它们的版本时仍然有效。", "desktop.settings.updates.applying": "正在用增量更新生成 Lithe {version}…", "desktop.settings.updates.auto": "自动检查更新", "desktop.settings.updates.autoHelp": "启动 5 秒后检查一次,之后每小时一次;窗口在后台时暂停,回到前台再补查。检查时更新服务器会看到你的 IP 地址。", diff --git a/desktop/internal/store/keep.go b/desktop/internal/store/keep.go new file mode 100644 index 0000000000..06e4556ae7 --- /dev/null +++ b/desktop/internal/store/keep.go @@ -0,0 +1,305 @@ +package store + +import ( + "bytes" + "encoding" + "encoding/json" + "reflect" + "sort" + "strings" +) + +// A file can hold settings this version of the client cannot read: a newer version wrote keys +// this one has no field for, or gave a known key a value of another shape. The stable channel +// and AutoBuild share one settings directory, so an install that moves between them meets both. +// Load finds them by walking the file against the type it decodes into, and Save writes them back +// beside what the value holds, so that running an older version and saving does not erase what +// the newer one stored. +// +// What a save writes back is only what this version cannot have changed: +// - a key no field reads, wherever its parent object is still written; +// - a known key whose stored value this version could not decode, as long as the value still +// encodes as it did right after the load. Once this version sets the field, its value wins +// and the stored one is dropped. +// +// A known key this version clears is gone from the next save, as before: the walk never keeps a +// key it can read. Arrays are kept or replaced whole; the walk does not look inside them. + +// keptObject is what one JSON object in a file holds that the value it decoded into cannot. +type keptObject struct { + // unknown are the keys no field reads, with their stored values. + unknown map[string]json.RawMessage + // foreign are the known keys whose stored value would not decode, by the name this + // version writes. + foreign map[string]*foreignValue + // inner are the known keys holding objects that keep something themselves, by the name this + // version writes. + inner map[string]*keptObject +} + +// foreignValue is a stored value the field could not take, and how the field encoded right after +// the load, nil when it was left out. +type foreignValue struct { + stored, loaded json.RawMessage +} + +func (object *keptObject) empty() bool { + return len(object.unknown) == 0 && len(object.foreign) == 0 && len(object.inner) == 0 +} + +// paths appends the dotted path of every key object keeps, under prefix. +func (object *keptObject) paths(prefix string, into []string) []string { + for key := range object.unknown { + into = append(into, prefix+key) + } + for key := range object.foreign { + into = append(into, prefix+key) + } + for key, inner := range object.inner { + into = inner.paths(prefix+key+".", into) + } + return into +} + +var ( + jsonUnmarshaler = reflect.TypeFor[json.Unmarshaler]() + textUnmarshaler = reflect.TypeFor[encoding.TextUnmarshaler]() +) + +// opaque reports whether values of t decode themselves, so their insides are not fields to walk. +func opaque(t reflect.Type) bool { + if t.Kind() == reflect.Interface { + return true + } + pointer := reflect.PointerTo(t) + return t.Implements(jsonUnmarshaler) || pointer.Implements(jsonUnmarshaler) || + t.Implements(textUnmarshaler) || pointer.Implements(textUnmarshaler) +} + +// walk compares the stored JSON value with the type it decodes into and returns what that type +// cannot hold, or nil when it holds everything. +func walk(stored json.RawMessage, t reflect.Type) *keptObject { + for t.Kind() == reflect.Pointer { + t = t.Elem() + } + if opaque(t) { + return nil + } + var object map[string]json.RawMessage + switch t.Kind() { + case reflect.Struct: + if json.Unmarshal(stored, &object) != nil || object == nil { + return nil + } + fields := fieldsOf(t) + kept := &keptObject{} + for _, key := range sortedKeys(object) { + value := object[key] + field, ok := fields.match(key) + switch { + case !ok: + kept.keepUnknown(key, value) + case !field.decodes(value): + kept.keepForeign(field.name, value) + default: + if inner := walk(value, field.typ); inner != nil { + kept.keepInner(field.name, inner) + } + } + } + if kept.empty() { + return nil + } + return kept + case reflect.Map: + if t.Key().Kind() != reflect.String || json.Unmarshal(stored, &object) != nil || object == nil { + return nil + } + element := field{typ: t.Elem()} + kept := &keptObject{} + for _, key := range sortedKeys(object) { + value := object[key] + if !element.decodes(value) { + kept.keepForeign(key, value) + } else if inner := walk(value, t.Elem()); inner != nil { + kept.keepInner(key, inner) + } + } + if kept.empty() { + return nil + } + return kept + } + return nil +} + +func (object *keptObject) keepUnknown(key string, value json.RawMessage) { + if object.unknown == nil { + object.unknown = map[string]json.RawMessage{} + } + object.unknown[key] = value +} + +func (object *keptObject) keepForeign(name string, value json.RawMessage) { + if object.foreign == nil { + object.foreign = map[string]*foreignValue{} + } + object.foreign[name] = &foreignValue{stored: value} +} + +func (object *keptObject) keepInner(name string, inner *keptObject) { + if object.inner == nil { + object.inner = map[string]*keptObject{} + } + object.inner[name] = inner +} + +// noteLoaded records how each foreign value's field encoded right after the load, from the value +// encoded as a whole. +func (object *keptObject) noteLoaded(encoded json.RawMessage) { + var current map[string]json.RawMessage + _ = json.Unmarshal(encoded, ¤t) + for name, foreign := range object.foreign { + foreign.loaded = compacted(current[name]) + } + for name, inner := range object.inner { + inner.noteLoaded(current[name]) + } +} + +// merge writes what object keeps into encoded, the object as this version encodes it now. An +// object this version no longer writes at all, such as a cleared pointer, gets nothing back. +// A foreign value whose field has changed since the load is dropped for good. +func (object *keptObject) merge(encoded json.RawMessage) json.RawMessage { + var current map[string]json.RawMessage + if json.Unmarshal(encoded, ¤t) != nil || current == nil { + return encoded + } + for key, value := range object.unknown { + if _, written := current[key]; !written { + current[key] = value + } + } + for name, foreign := range object.foreign { + now, written := current[name] + unchanged := (!written && foreign.loaded == nil) || + (written && foreign.loaded != nil && bytes.Equal(compacted(now), foreign.loaded)) + if !unchanged { + delete(object.foreign, name) + continue + } + current[name] = foreign.stored + } + for name, inner := range object.inner { + if now, written := current[name]; written { + current[name] = inner.merge(now) + } + } + merged, err := json.Marshal(current) + if err != nil { + return encoded + } + return merged +} + +// field is one key a struct reads: the name it writes and the type it decodes into. +type field struct { + name string + typ reflect.Type + // quoted is the ",string" option: the value is a JSON string holding the field's. + quoted bool +} + +// decodes reports whether value has a shape the field can take. A struct or map only has to be +// an object, because walk looks inside it; anything else has to decode whole. +func (f field) decodes(value json.RawMessage) bool { + t := f.typ + for t.Kind() == reflect.Pointer { + t = t.Elem() + } + trimmed := bytes.TrimSpace(value) + if bytes.Equal(trimmed, []byte("null")) || f.quoted { + return true + } + if !opaque(t) && (t.Kind() == reflect.Struct || t.Kind() == reflect.Map) { + return len(trimmed) > 0 && trimmed[0] == '{' + } + return json.Unmarshal(value, reflect.New(f.typ).Interface()) == nil +} + +type fields []field + +// match finds the field encoding/json would decode key into: the exact name first, then one that +// differs only in case. +func (list fields) match(key string) (field, bool) { + for _, candidate := range list { + if candidate.name == key { + return candidate, true + } + } + for _, candidate := range list { + if strings.EqualFold(candidate.name, key) { + return candidate, true + } + } + return field{}, false +} + +// fieldsOf lists the keys a struct type reads, as encoding/json names them: the tag name or the +// field name, skipping "-" and unexported fields, with the fields of an untagged embedded struct +// promoted. +func fieldsOf(t reflect.Type) fields { + var list fields + for index := range t.NumField() { + structField := t.Field(index) + tag := structField.Tag.Get("json") + if tag == "-" { + continue + } + name, options, _ := strings.Cut(tag, ",") + fieldType := structField.Type + if structField.Anonymous && name == "" { + embedded := fieldType + for embedded.Kind() == reflect.Pointer { + embedded = embedded.Elem() + } + if embedded.Kind() == reflect.Struct { + list = append(list, fieldsOf(embedded)...) + continue + } + } + if !structField.IsExported() { + continue + } + if name == "" { + name = structField.Name + } + quoted := false + for option := range strings.SplitSeq(options, ",") { + quoted = quoted || option == "string" + } + list = append(list, field{name: name, typ: fieldType, quoted: quoted}) + } + return list +} + +func sortedKeys(object map[string]json.RawMessage) []string { + keys := make([]string, 0, len(object)) + for key := range object { + keys = append(keys, key) + } + sort.Strings(keys) + return keys +} + +// compacted is value without insignificant space, nil for no value. +func compacted(value json.RawMessage) json.RawMessage { + if value == nil { + return nil + } + var buffer bytes.Buffer + if json.Compact(&buffer, value) != nil { + return value + } + return buffer.Bytes() +} diff --git a/desktop/internal/store/keep_test.go b/desktop/internal/store/keep_test.go new file mode 100644 index 0000000000..e13e99a9d2 --- /dev/null +++ b/desktop/internal/store/keep_test.go @@ -0,0 +1,191 @@ +package store + +import ( + "encoding/json" + "os" + "path/filepath" + "reflect" + "testing" +) + +// olderSettings is a settings file as an older version knows it: fewer keys than a newer +// version writes. +type olderSettings struct { + Theme string `json:"theme,omitempty"` + Count int `json:"count,omitempty"` + Editor *olderEditor `json:"editor,omitempty"` + Hosts map[string]olderH `json:"hosts,omitempty"` + olderEmbedded +} + +type olderEditor struct { + Size int `json:"size,omitempty"` +} + +type olderH struct { + Port int `json:"port,omitempty"` +} + +type olderEmbedded struct { + Shared string `json:"shared,omitempty"` +} + +// writeFile puts content in dir/name for a store to load. +func writeFile(t *testing.T, dir, name, content string) { + t.Helper() + if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644); err != nil { + t.Fatal(err) + } +} + +// readObject decodes dir/name as a JSON object for comparison. +func readObject(t *testing.T, dir, name string) map[string]any { + t.Helper() + data, err := os.ReadFile(filepath.Join(dir, name)) + if err != nil { + t.Fatal(err) + } + var object map[string]any + if err := json.Unmarshal(data, &object); err != nil { + t.Fatalf("the saved file is not a JSON object: %v\n%s", err, data) + } + return object +} + +func TestSaveKeepsKeysANewerVersionWrote(t *testing.T) { + dir := t.TempDir() + writeFile(t, dir, "settings.json", `{ + "theme": "dark", + "updateChannel": "autobuild", + "editor": {"size": 13, "ligatures": true}, + "hosts": {"a": {"port": 22, "proxy": "jump"}}, + "shared": "yes" +}`) + store := At(dir) + var value olderSettings + if found, err := store.Load("settings.json", &value); !found || err != nil { + t.Fatalf("Load = %v, %v", found, err) + } + if value.Theme != "dark" || value.Editor == nil || value.Editor.Size != 13 || value.Hosts["a"].Port != 22 || value.Shared != "yes" { + t.Fatalf("Load = %+v", value) + } + if got, want := store.Unknown("settings.json"), []string{"editor.ligatures", "hosts.a.proxy", "updateChannel"}; !reflect.DeepEqual(got, want) { + t.Fatalf("Unknown = %v, want %v", got, want) + } + + value.Theme = "light" + if err := store.Save("settings.json", value); err != nil { + t.Fatal(err) + } + saved := readObject(t, dir, "settings.json") + want := map[string]any{ + "theme": "light", + "updateChannel": "autobuild", + "editor": map[string]any{"size": float64(13), "ligatures": true}, + "hosts": map[string]any{"a": map[string]any{"port": float64(22), "proxy": "jump"}}, + "shared": "yes", + } + if !reflect.DeepEqual(saved, want) { + t.Fatalf("saved %v\nwant %v", saved, want) + } +} + +func TestSaveDoesNotReviveAKnownKeyThisVersionCleared(t *testing.T) { + dir := t.TempDir() + writeFile(t, dir, "settings.json", `{"theme": "dark", "editor": {"size": 13, "ligatures": true}, "hosts": {"a": {"proxy": "jump"}}, "later": 1}`) + store := At(dir) + var value olderSettings + if _, err := store.Load("settings.json", &value); err != nil { + t.Fatal(err) + } + // The user clears the theme, removes the editor block and the host: none comes back, and a + // removed object takes the keys inside it along. + value.Theme = "" + value.Editor = nil + delete(value.Hosts, "a") + if err := store.Save("settings.json", value); err != nil { + t.Fatal(err) + } + if saved, want := readObject(t, dir, "settings.json"), map[string]any{"later": float64(1)}; !reflect.DeepEqual(saved, want) { + t.Fatalf("saved %v, want %v", saved, want) + } +} + +func TestLoadKeepsAValueOfAShapeThisVersionCannotRead(t *testing.T) { + dir := t.TempDir() + // A newer version turned count into an object; the rest of the file still loads. + writeFile(t, dir, "settings.json", `{"theme": "dark", "count": {"value": 3}, "editor": {"size": "large"}}`) + store := At(dir) + value := olderSettings{Count: 7} + if found, err := store.Load("settings.json", &value); !found || err != nil { + t.Fatalf("Load = %v, %v; want the readable keys loaded", found, err) + } + if value.Theme != "dark" || value.Count != 7 { + t.Fatalf("Load = %+v, want the theme read and count left at its default", value) + } + if got, want := store.Unknown("settings.json"), []string{"count", "editor.size"}; !reflect.DeepEqual(got, want) { + t.Fatalf("Unknown = %v, want %v", got, want) + } + + if err := store.Save("settings.json", value); err != nil { + t.Fatal(err) + } + saved := readObject(t, dir, "settings.json") + if want := map[string]any{"value": float64(3)}; !reflect.DeepEqual(saved["count"], want) { + t.Fatalf("count = %v, want the stored %v back", saved["count"], want) + } + if want := map[string]any{"size": "large"}; !reflect.DeepEqual(saved["editor"], want) { + t.Fatalf("editor = %v, want the stored %v back", saved["editor"], want) + } + + // Once this version sets the field itself, its value wins and stays. + value.Count = 9 + if err := store.Save("settings.json", value); err != nil { + t.Fatal(err) + } + value.Count = 7 + if err := store.Save("settings.json", value); err != nil { + t.Fatal(err) + } + if saved := readObject(t, dir, "settings.json"); saved["count"] != float64(7) { + t.Fatalf("count = %v, want this version's 7", saved["count"]) + } +} + +func TestSaveWithNothingUnknownWritesTheValueAsBefore(t *testing.T) { + dir := t.TempDir() + writeFile(t, dir, "settings.json", `{"theme": "dark"}`) + store := At(dir) + var value olderSettings + if _, err := store.Load("settings.json", &value); err != nil { + t.Fatal(err) + } + if unknown := store.Unknown("settings.json"); unknown != nil { + t.Fatalf("Unknown = %v, want none", unknown) + } + if err := store.Save("settings.json", value); err != nil { + t.Fatal(err) + } + data, err := os.ReadFile(filepath.Join(dir, "settings.json")) + if err != nil { + t.Fatal(err) + } + want, _ := json.MarshalIndent(value, "", " ") + if string(data) != string(want)+"\n" { + t.Fatalf("saved %q, want %q", data, string(want)+"\n") + } +} + +func TestLoadMatchesKeysAsEncodingJSONDoes(t *testing.T) { + dir := t.TempDir() + // encoding/json reads "Theme" into the theme field, so it is not unknown. + writeFile(t, dir, "settings.json", `{"Theme": "dark"}`) + store := At(dir) + var value olderSettings + if _, err := store.Load("settings.json", &value); err != nil { + t.Fatal(err) + } + if value.Theme != "dark" || store.Unknown("settings.json") != nil { + t.Fatalf("Load = %+v, Unknown = %v", value, store.Unknown("settings.json")) + } +} diff --git a/desktop/internal/store/store.go b/desktop/internal/store/store.go index 6a46d748ea..466514e2ba 100644 --- a/desktop/internal/store/store.go +++ b/desktop/internal/store/store.go @@ -6,15 +6,22 @@ // Each file belongs to one owner (recent projects, workbench layout, settings) and is // replaced whole on every save through a temporary file in the same directory, so a crash // leaves either the previous or the new content, never a half-written file. +// +// A save keeps what the last load of the same file could not read, such as keys a newer version +// wrote (see keep.go), so moving between the stable channel and AutoBuild loses no settings. package store import ( + "bytes" "encoding/json" "errors" "fmt" "io/fs" "os" "path/filepath" + "reflect" + "sort" + "sync" ) // Directory is the name of the client's folder inside the user configuration directory. @@ -23,6 +30,10 @@ const Directory = "Lithe Desktop" // Store reads and writes the client's preference files in one directory. type Store struct { dir string + + mu sync.Mutex + // kept is, per file, what its last load found that the value could not hold. + kept map[string]*keptObject } // Open returns the store in the user's configuration directory. The directory is created @@ -47,27 +58,101 @@ func (store *Store) Dir() string { // Load decodes the file name into value. found is false, and value untouched, when the // file does not exist yet. +// +// Keys value has no field for, and known keys whose stored value has a shape the field cannot +// take, do not fail the load: the fields keep what value held, and the next Save of name writes +// the stored values back. Unknown lists them. A file that is not JSON still fails. func (store *Store) Load(name string, value any) (found bool, err error) { data, err := os.ReadFile(filepath.Join(store.dir, name)) if errors.Is(err, fs.ErrNotExist) { + store.keep(name, nil) return false, nil } if err != nil { return false, err } - if err := json.Unmarshal(data, value); err != nil { - return true, fmt.Errorf("decode %s: %w", name, err) + decodeErr := json.Unmarshal(data, value) + kept := walk(data, reflect.TypeOf(value)) + if decodeErr != nil && (kept == nil || !foreignAnywhere(kept)) { + store.keep(name, nil) + return true, fmt.Errorf("decode %s: %w", name, decodeErr) } + if kept != nil { + if encoded, err := json.Marshal(value); err == nil { + kept.noteLoaded(encoded) + } + } + store.keep(name, kept) return true, nil } -// Save encodes value and replaces the file name with it atomically. +// foreignAnywhere reports whether the walk found a known key it could not decode, the only kind +// of failure json.Unmarshal reports and then completes the value anyway. +func foreignAnywhere(object *keptObject) bool { + if len(object.foreign) > 0 { + return true + } + for _, inner := range object.inner { + if foreignAnywhere(inner) { + return true + } + } + return false +} + +func (store *Store) keep(name string, kept *keptObject) { + store.mu.Lock() + defer store.mu.Unlock() + if kept == nil { + delete(store.kept, name) + return + } + if store.kept == nil { + store.kept = map[string]*keptObject{} + } + store.kept[name] = kept +} + +// Unknown lists, as dotted key paths, what the last load of name could not read and the next save +// writes back: keys a newer version wrote, and values of a shape this version cannot take. +func (store *Store) Unknown(name string) []string { + store.mu.Lock() + defer store.mu.Unlock() + kept := store.kept[name] + if kept == nil { + return nil + } + paths := kept.paths("", nil) + sort.Strings(paths) + return paths +} + +// Save encodes value and replaces the file name with it atomically, with what the last load of +// name could not read written back beside it. func (store *Store) Save(name string, value any) error { - data, err := json.MarshalIndent(value, "", " ") + store.mu.Lock() + kept := store.kept[name] + store.mu.Unlock() + if kept == nil { + data, err := json.MarshalIndent(value, "", " ") + if err != nil { + return fmt.Errorf("encode %s: %w", name, err) + } + return store.WriteFile(name, append(data, '\n')) + } + encoded, err := json.Marshal(value) if err != nil { return fmt.Errorf("encode %s: %w", name, err) } - return store.WriteFile(name, append(data, '\n')) + store.mu.Lock() + merged := kept.merge(encoded) + store.mu.Unlock() + var data bytes.Buffer + if err := json.Indent(&data, merged, "", " "); err != nil { + return fmt.Errorf("encode %s: %w", name, err) + } + data.WriteByte('\n') + return store.WriteFile(name, data.Bytes()) } // Path is where the file name lives, for a reader that streams it instead of loading it whole, @@ -78,6 +163,7 @@ func (store *Store) Path(name string) string { // Remove deletes the file name. A file that does not exist is already removed. func (store *Store) Remove(name string) error { + store.keep(name, nil) if err := os.Remove(filepath.Join(store.dir, name)); err != nil && !errors.Is(err, fs.ErrNotExist) { return err } diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index d05887c9ef..b0cc4dc7f7 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -354,6 +354,9 @@ type settings struct { // WorkbenchBackground is the image chosen to show behind the workbench and how much of it // shows; the image itself is a copy in the data folder (workbench_background.go). WorkbenchBackground savedBackground `json:"workbenchBackground,omitzero"` + // UnknownSettingsNoticed names the set of settings this version could not read that the + // first window last told about, so the same set is told once (settings_kept.go). + UnknownSettingsNoticed string `json:"unknownSettingsNoticed,omitempty"` } const ( @@ -798,6 +801,11 @@ func New(options Options) *App { a.loadChrome() if options.first == nil && a.store != nil { a.restoreBackground() + if settingsErr == nil { + // After the background is restored: the notice saves the settings, which would + // otherwise save no background. + a.noticeUnknownSettings() + } } return a } diff --git a/desktop/internal/workbench/settings_kept.go b/desktop/internal/workbench/settings_kept.go new file mode 100644 index 0000000000..3425a48b00 --- /dev/null +++ b/desktop/internal/workbench/settings_kept.go @@ -0,0 +1,55 @@ +package workbench + +import ( + "crypto/sha256" + "encoding/hex" + "strconv" + "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// The stable channel and AutoBuild share one settings file, so the build that runs may meet +// settings only a newer build knows: keys it has no field for, or a known key holding a value of +// another shape. The store keeps them on every save (store.Store.Unknown), and this version +// ignores them. The first window says so once for each set of such keys, so that moving between +// channels does not look like settings were lost; the set it told about is saved +// (settings.UnknownSettingsNoticed), and the same set says nothing on the next launch. + +// unknownSettingsNamed is how many of the kept keys the notice names. +const unknownSettingsNamed = 5 + +// noticeUnknownSettings tells, once per set, about the settings the file holds that this version +// does not read. It runs on the first window after the settings are loaded. +func (a *App) noticeUnknownSettings() { + if a.store == nil { + return + } + unknown := a.store.Unknown(settingsFile) + fingerprint := unknownSettingsFingerprint(unknown) + if fingerprint == a.settings.UnknownSettingsNoticed { + return + } + a.settings.UnknownSettingsNoticed = fingerprint + a.saveSettings() + if len(unknown) == 0 { + return + } + named := unknown + if len(named) > unknownSettingsNamed { + named = append(named[:unknownSettingsNamed:unknownSettingsNamed], "…") + } + a.notifyInfo(i18n.SharedFormat(a.language(), "desktop.settings.unknownKept", map[string]string{ + "count": strconv.Itoa(len(unknown)), + "keys": strings.Join(named, ", "), + })) +} + +// unknownSettingsFingerprint names a set of kept keys in a few characters, empty for none. +func unknownSettingsFingerprint(keys []string) string { + if len(keys) == 0 { + return "" + } + sum := sha256.Sum256([]byte(strings.Join(keys, "\n"))) + return hex.EncodeToString(sum[:8]) +} diff --git a/desktop/internal/workbench/settings_kept_test.go b/desktop/internal/workbench/settings_kept_test.go new file mode 100644 index 0000000000..9e0e1f455c --- /dev/null +++ b/desktop/internal/workbench/settings_kept_test.go @@ -0,0 +1,55 @@ +package workbench + +import ( + "encoding/json" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" +) + +// keptNotices is the notices that told about settings this version does not read. +func keptNotices(a *App) []string { + var found []string + for _, entry := range a.notifications.list { + if strings.Contains(entry.text, "laterChannelOption") { + found = append(found, entry.text) + } + } + return found +} + +func TestSettingsANewerVersionWroteAreToldAboutOnceAndKept(t *testing.T) { + dir := t.TempDir() + written := `{"theme":"dark","laterChannelOption":"nightly","workbenchBackground":{"name":"bg.png","strength":"strong"}}` + if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(written), 0o600); err != nil { + t.Fatal(err) + } + first := newHarnessWithOptions(t, Options{Kernel: &testKernel{Client: core.NewClient()}, Store: store.At(dir), Languages: []string{"zh-Hans"}}) + if notices := keptNotices(first.app); len(notices) != 1 || !strings.Contains(notices[0], "1") { + t.Fatalf("notices at the first launch = %q, want one naming the kept key", notices) + } + + data, err := os.ReadFile(filepath.Join(dir, settingsFile)) + if err != nil { + t.Fatal(err) + } + var saved map[string]any + if err := json.Unmarshal(data, &saved); err != nil { + t.Fatal(err) + } + if saved["laterChannelOption"] != "nightly" { + t.Fatalf("saved %s, want the key this version does not read kept", data) + } + if background, _ := saved["workbenchBackground"].(map[string]any); background["name"] != "bg.png" { + t.Fatalf("saved %s, want the background the notice's save left alone", data) + } + + second := newHarnessWithOptions(t, Options{Kernel: &testKernel{Client: core.NewClient()}, Store: store.At(dir), Languages: []string{"zh-Hans"}}) + if notices := keptNotices(second.app); len(notices) != 0 { + t.Fatalf("notices at the next launch = %q, want none for the same keys", notices) + } +} diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 6fff88a7ec..76620d7987 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -10988,6 +10988,7 @@ "desktop.settings.updates.check": "Check Now", "desktop.settings.updates.notes": "Release Notes", "desktop.updates.available": "Lithe {version} is available. Open Settings > About to update.", + "desktop.settings.unknownKept": "The settings file has {count} settings this version does not recognize ({keys}). This version ignores them but keeps them, so they still apply when you switch back to a version that knows them.", "desktop.memory.status": "{total} · Lithe {lithe}", "desktop.memory.tooltip": "Memory: {total} in total, {lithe} of it in the Lithe main process.", "desktop.memory.title": "Memory", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 202277ec8b..3960aee22d 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -10988,6 +10988,7 @@ "desktop.settings.updates.check": "立即检查", "desktop.settings.updates.notes": "发布说明", "desktop.updates.available": "Lithe {version} 已发布,可在“设置 > 关于”中一键更新。", + "desktop.settings.unknownKept": "设置文件中有 {count} 项此版本无法识别的设置({keys})。此版本不会使用它们,但会原样保留,换回能识别它们的版本时仍然有效。", "desktop.memory.status": "{total} · Lithe {lithe}", "desktop.memory.tooltip": "内存:共 {total},其中 Lithe 主进程 {lithe}。", "desktop.memory.title": "内存", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index c82564a01a..2e389d4fb6 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -17758,6 +17758,17 @@ "version": "string" } }, + { + "id": "desktop.settings.unknownKept", + "description": "Notice at launch when settings.json holds settings this version does not recognize, such as ones a newer build or the other update channel wrote. They are ignored but kept in the file. {count} is how many, {keys} names up to five of them.", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string", + "keys": "string" + } + }, { "id": "desktop.vcs.commitDirectly", "description": "Hint under the commit button of a plugin version control window whose provider sends a commit to the repository right away, with no separate push.", From 918a64eb881d2329d5da66786159499fb45f6924 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 15 Nov 2026 23:56:54 +0800 Subject: [PATCH 04/10] feat(desktop): update channels, feed sources, skip and kept settings - Two channels, stable and AutoBuild, each with a configurable feed that defaults to the 1lck/Lithe-IDEA release feed. The installed channel is the default; the user's switch, "switch now" and "restore" choices are saved. - Switching compares the other channel's feed with a version of its own (0.0.0, or the release AutoBuild is building towards when waiting), forgets the last check, and never runs during a download or install. Cross-channel releases install in full. - Skip This Version per channel; the arrow and notice stay away until a newer version arrives. A check the user asks for still finds it. - Release notes are read unsigned from .notes.md after the signed check, need a matching version header, and are cut at 16 KB. - Moving to the other channel keeps settings.json in update-snapshots in the preferences directory (5 newest kept); a restore is applied by the next launch of exactly that channel and version, keeping the update settings. - Installs that cannot replace themselves say why and offer the downloads page. Refs #1913 --- desktop/internal/buildinfo/update.go | 68 ++- desktop/internal/i18n/shared.generated.go | 92 ++- desktop/internal/settingswindow/controller.go | 10 + .../internal/settingswindow/updates_view.go | 49 +- desktop/internal/workbench/app.go | 22 +- desktop/internal/workbench/notifications.go | 37 +- desktop/internal/workbench/settings.go | 8 +- desktop/internal/workbench/update_channels.go | 252 +++++++++ .../workbench/update_channels_test.go | 523 ++++++++++++++++++ desktop/internal/workbench/update_notes.go | 153 +++++ .../internal/workbench/update_snapshots.go | 243 ++++++++ desktop/internal/workbench/updates.go | 248 +++++++-- desktop/internal/workbench/updates_test.go | 30 +- shared/i18n/locales/en-US.json | 46 +- shared/i18n/locales/zh-CN.json | 46 +- shared/i18n/messages.json | 364 +++++++++++- 16 files changed, 2107 insertions(+), 84 deletions(-) create mode 100644 desktop/internal/workbench/update_channels.go create mode 100644 desktop/internal/workbench/update_channels_test.go create mode 100644 desktop/internal/workbench/update_notes.go create mode 100644 desktop/internal/workbench/update_snapshots.go diff --git a/desktop/internal/buildinfo/update.go b/desktop/internal/buildinfo/update.go index 711d4d766d..2931c0eb10 100644 --- a/desktop/internal/buildinfo/update.go +++ b/desktop/internal/buildinfo/update.go @@ -1,18 +1,66 @@ package buildinfo -// The update feed a release build checks, set at link time -// (-X github.com/1lck/Lithe-IDEA/desktop/internal/buildinfo.UpdateFeedURL=...). A build -// without them does not check for updates: development and local builds never replace -// themselves. +import "strings" + +// Lithe updates from one of two channels: the stable releases, which go through the release +// process, and AutoBuild, built from main every day. Each has its own signed feed. The channel a +// build was packaged for, when and from which commit, and the keys the feeds are signed with are +// set at link time by scripts/desktop/package-desktop.sh, with +// -X github.com/1lck/Lithe-IDEA/desktop/internal/buildinfo.=. A build without a +// channel, a development or local build, never replaces itself. +const ( + ChannelStable = "stable" + ChannelAutoBuild = "autobuild" +) + +// Channels are the update channels, in the order the settings list them. +var Channels = []string{ChannelStable, ChannelAutoBuild} + var ( - // UpdateFeedURL is the HTTPS address of the signed latest.json. - UpdateFeedURL string - // UpdatePublicKeys are the Ed25519 keys the feed may be signed with, base64, - // separated by commas, so a key can be rotated. + // Channel is the channel the build was packaged for: ChannelStable or ChannelAutoBuild. + Channel string + // BuildTime is when the build was packaged, in RFC 3339 and UTC. + BuildTime string + // Commit is the Git commit the build was packaged from. + Commit string + // UpdatePublicKeys are the Ed25519 keys a feed may be signed with, base64, separated by + // commas, so a key can be rotated. Both channels and every feed address the user sets are + // checked against them. UpdatePublicKeys string - // UpdateChannel is the release channel the build follows, such as "stable". - UpdateChannel string + // StableFeedURL and AutoBuildFeedURL are the default feeds of the channels, on the official + // repository's desktop-update-feed release. A fork that signs its own feeds sets them. + StableFeedURL = "https://github.com/1lck/Lithe-IDEA/releases/download/desktop-update-feed/stable.json" + AutoBuildFeedURL = "https://github.com/1lck/Lithe-IDEA/releases/download/desktop-update-feed/autobuild.json" + // DownloadsURL is where a user downloads Lithe by hand, for an installation that cannot + // update itself. + DownloadsURL = "https://github.com/1lck/Lithe-IDEA/releases" ) // UpdateApp is the identifier the feed and the installed application carry. const UpdateApp = "app.lithe.viva" + +// InstalledChannel is the channel the running build was packaged for, empty for a development +// or local build, which does not update. +func InstalledChannel() string { + if Development { + return "" + } + return KnownChannel(Channel) +} + +// KnownChannel is channel when it names one of the channels, else empty. +func KnownChannel(channel string) string { + switch channel = strings.TrimSpace(channel); channel { + case ChannelStable, ChannelAutoBuild: + return channel + } + return "" +} + +// DefaultFeedURL is the feed a channel reads unless the user set another. +func DefaultFeedURL(channel string) string { + if channel == ChannelAutoBuild { + return AutoBuildFeedURL + } + return StableFeedURL +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 2d21c70096..788a33bd3e 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1450,22 +1450,45 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.updates.autoHelp": "Checks 5 seconds after launch, then every hour. Checks pause while the window is in the background and catch up when it returns. The update server sees your IP address when Lithe checks.", "desktop.settings.updates.available": "Lithe {version} is available.", "desktop.settings.updates.availableDelta": "Lithe {version} is available as a {size} delta update ({full} in full).", + "desktop.settings.updates.build": "{channel} · built {time} · commit {commit}", + "desktop.settings.updates.channel": "Update channel", + "desktop.settings.updates.channelBusy": "The channel and feeds can't change while an update downloads or installs.", + "desktop.settings.updates.channelHelp": "Stable gets released versions only. AutoBuild is built from every merge to main: newer, but it may break. Both channels share settings.", "desktop.settings.updates.check": "Check Now", "desktop.settings.updates.checking": "Checking for updates…", + "desktop.settings.updates.cross": "Lithe {version} from {channel} can be installed and replaces this build in full.", "desktop.settings.updates.downloading": "Downloading Lithe {version}… {percent}%", "desktop.settings.updates.downloadingDelta": "Downloading the Lithe {version} delta update… {percent}%", "desktop.settings.updates.downloadingFull": "The delta update could not be used. Downloading Lithe {version} in full… {percent}%", "desktop.settings.updates.failed": "Update failed: {reason}", "desktop.settings.updates.help": "Lithe checks a signed release feed and installs the new version after you confirm. When the feed offers a delta update, only what changed is downloaded. The current version stays in place until the new one starts.", + "desktop.settings.updates.installed": "This build", "desktop.settings.updates.installing": "Installing and restarting…", "desktop.settings.updates.lastChecked": "Last checked {time}", + "desktop.settings.updates.local": "This is a local development build. It belongs to no update channel and does not check for updates.", "desktop.settings.updates.notConfigured": "This build has no update feed. Install new versions from the release page.", "desktop.settings.updates.notes": "Release Notes", "desktop.settings.updates.ready": "Lithe {version} is downloaded. Click Update to install and restart.", + "desktop.settings.updates.restore": "Restore my settings from when I last used {channel}", + "desktop.settings.updates.restoreHelp": "The new build starts with the snapshot saved then; update settings keep their current values. Leave it off to keep your current settings.", "desktop.settings.updates.row": "Check for Updates", + "desktop.settings.updates.skipped": "Lithe {version} is skipped. You'll be told about the next one.", + "desktop.settings.updates.source": "{channel} feed", + "desktop.settings.updates.sourceDefault": "Default ({repo})", + "desktop.settings.updates.sourceHelp": "A feed is a signed JSON file. Lithe installs only releases whose signature this build can verify.", + "desktop.settings.updates.sourceInvalid": "A feed must be an https:// address.", + "desktop.settings.updates.sourceReset": "Restore Default", + "desktop.settings.updates.sourceSave": "Save", "desktop.settings.updates.title": "Updates", + "desktop.settings.updates.toAutoBuild.body": "AutoBuild is built from every merge to main without release testing, so it may have bugs. Lithe checks AutoBuild's latest build at once and shows what changed before you choose to download it; it replaces this build in full.", + "desktop.settings.updates.toAutoBuild.title": "Switch to AutoBuild?", + "desktop.settings.updates.toStable.body": "Wait for the first stable release after {version}, so nothing older is installed, or install the latest stable release now, which may be older than this build.", + "desktop.settings.updates.toStable.now": "Switch Now", + "desktop.settings.updates.toStable.title": "Switch Back to Stable?", + "desktop.settings.updates.toStable.wait": "Wait for Next Release", "desktop.settings.updates.upToDate": "Lithe {version} is up to date.", "desktop.settings.updates.update": "Update", + "desktop.settings.updates.waiting": "Lithe moves back to Stable with the first stable release after {version}.", "desktop.startupSweep.body": "{arg1} processes started by an earlier run of Lithe are still running. Ending them stops them.", "desktop.startupSweep.end": "End them", "desktop.startupSweep.item": "{arg1} PID {arg2} {arg3}", @@ -1651,7 +1674,28 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tools.moveTo": "Move to", "desktop.tools.structure": "Structure", "desktop.tools.withShortcut": "{name} {keys}", - "desktop.updates.available": "Lithe {version} is available. Open Settings > About to update.", + "desktop.updates.arrow.available": "Lithe {version} is available. Click to see what changed", + "desktop.updates.arrow.downloading": "Downloading Lithe {version}… {percent}%", + "desktop.updates.arrow.ready": "Lithe {version} is downloaded. Click to restart and update", + "desktop.updates.available": "Lithe {version} is available. Click the green arrow at the top right of the title bar to see what changed.", + "desktop.updates.channel.autobuild": "AutoBuild", + "desktop.updates.channel.stable": "Stable", + "desktop.updates.dialog.cross": "This release is from the {channel} channel and replaces this build in full. Both channels share settings; a snapshot of your current settings is saved before it installs.", + "desktop.updates.dialog.current": "You have {version} · {channel}", + "desktop.updates.dialog.download": "Download and Install", + "desktop.updates.dialog.downloads": "Open Downloads Page", + "desktop.updates.dialog.fullNotes": "Full Notes on GitHub", + "desktop.updates.dialog.later": "Later", + "desktop.updates.dialog.noNotes": "This release has no notes.", + "desktop.updates.dialog.notesLoading": "Loading what's new…", + "desktop.updates.dialog.restart": "Restart and Update", + "desktop.updates.dialog.sizeDelta": "Delta update {size} (full package {full})", + "desktop.updates.dialog.sizeFull": "Full package {size}", + "desktop.updates.dialog.skip": "Skip This Version", + "desktop.updates.dialog.title": "Lithe {version} Is Available", + "desktop.updates.manual.managed": "This copy of Lithe is managed by a package manager. Update it there, or install the new version from the downloads page.", + "desktop.updates.manual.notWritable": "Lithe can't replace the app where it is installed. Install the new version from the downloads page.", + "desktop.updates.viewChanges": "View Changes", "desktop.vcs.commitDirectly": "Commits are sent to the repository right away; there is no separate push.", "desktop.viewer.binaryHint": "This file is not text. Its first bytes are shown in hex, read only.", "desktop.viewer.close": "Close", @@ -4065,22 +4109,45 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.updates.autoHelp": "启动 5 秒后检查一次,之后每小时一次;窗口在后台时暂停,回到前台再补查。检查时更新服务器会看到你的 IP 地址。", "desktop.settings.updates.available": "Lithe {version} 可更新。", "desktop.settings.updates.availableDelta": "Lithe {version} 可更新,增量更新 {size}(完整安装包 {full})。", + "desktop.settings.updates.build": "{channel} · 构建于 {time} · 提交 {commit}", + "desktop.settings.updates.channel": "更新渠道", + "desktop.settings.updates.channelBusy": "下载或安装更新期间不能切换渠道或修改发布源。", + "desktop.settings.updates.channelHelp": "正式版只收到发布过的稳定版本;AutoBuild 由 main 上的每次合入自动构建,更新更快但可能不稳定。两个渠道共用设置。", "desktop.settings.updates.check": "立即检查", "desktop.settings.updates.checking": "正在检查更新…", + "desktop.settings.updates.cross": "{channel}的 Lithe {version} 可安装,会完整替换当前构建。", "desktop.settings.updates.downloading": "正在下载 Lithe {version}… {percent}%", "desktop.settings.updates.downloadingDelta": "正在下载 Lithe {version} 的增量更新… {percent}%", "desktop.settings.updates.downloadingFull": "增量更新无法使用,改为下载完整的 Lithe {version}… {percent}%", "desktop.settings.updates.failed": "更新失败:{reason}", "desktop.settings.updates.help": "Lithe 从带签名的发布源检查新版本,经你确认后安装;发布源提供增量更新时只下载改动的部分。新版本启动前,当前版本保持不变。", + "desktop.settings.updates.installed": "当前构建", "desktop.settings.updates.installing": "正在安装并重启…", "desktop.settings.updates.lastChecked": "上次检查:{time}", + "desktop.settings.updates.local": "这是本地开发构建,不属于任何更新渠道,也不会检查更新。", "desktop.settings.updates.notConfigured": "此构建未配置更新源,请从发布页面安装新版本。", "desktop.settings.updates.notes": "发布说明", "desktop.settings.updates.ready": "Lithe {version} 已下载,点“更新”即可安装并重启。", + "desktop.settings.updates.restore": "恢复上次使用{channel}时的设置", + "desktop.settings.updates.restoreHelp": "新版本首次启动时换回当时保存的设置快照,更新相关的设置保持现在的值。不勾选则继续使用当前设置。", "desktop.settings.updates.row": "检查更新", + "desktop.settings.updates.skipped": "已跳过 Lithe {version},有更新的版本时会再提示。", + "desktop.settings.updates.source": "{channel}发布源", + "desktop.settings.updates.sourceDefault": "默认({repo})", + "desktop.settings.updates.sourceHelp": "发布源是一份带签名的 JSON 文件,Lithe 只安装签名能被当前构建验证的版本。", + "desktop.settings.updates.sourceInvalid": "发布源必须是 https:// 地址。", + "desktop.settings.updates.sourceReset": "恢复默认", + "desktop.settings.updates.sourceSave": "保存", "desktop.settings.updates.title": "更新", + "desktop.settings.updates.toAutoBuild.body": "AutoBuild 由 main 上的每次合入自动构建,没有经过发布测试,可能有缺陷。切换后 Lithe 会立即检查 AutoBuild 的最新构建,先显示更新内容,由你决定是否下载;它会完整替换当前构建。", + "desktop.settings.updates.toAutoBuild.title": "切换到 AutoBuild?", + "desktop.settings.updates.toStable.body": "可以等正式版发布 {version} 之后的版本再切换,不会装回更旧的版本;也可以立即安装正式版现在的最新版本,它可能比当前构建旧。", + "desktop.settings.updates.toStable.now": "立即切换", + "desktop.settings.updates.toStable.title": "切回正式版?", + "desktop.settings.updates.toStable.wait": "等下一个正式版", "desktop.settings.updates.upToDate": "Lithe {version} 已是最新版本。", "desktop.settings.updates.update": "更新", + "desktop.settings.updates.waiting": "正式版发布 {version} 之后的版本时切回正式版。", "desktop.startupSweep.body": "上次运行 Lithe 启动的 {arg1} 个进程仍在运行。结束它们会停止这些进程。", "desktop.startupSweep.end": "结束这些进程", "desktop.startupSweep.item": "{arg1} PID {arg2} {arg3}", @@ -4266,7 +4333,28 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tools.moveTo": "移动到", "desktop.tools.structure": "结构", "desktop.tools.withShortcut": "{name} {keys}", - "desktop.updates.available": "Lithe {version} 已发布,可在“设置 > 关于”中一键更新。", + "desktop.updates.arrow.available": "Lithe {version} 可更新,点击查看更新内容", + "desktop.updates.arrow.downloading": "正在下载 Lithe {version}… {percent}%", + "desktop.updates.arrow.ready": "Lithe {version} 已下载,点击重启并更新", + "desktop.updates.available": "Lithe {version} 已发布,点标题栏右上角的绿色箭头查看更新内容。", + "desktop.updates.channel.autobuild": "AutoBuild", + "desktop.updates.channel.stable": "正式版", + "desktop.updates.dialog.cross": "这是{channel}渠道的版本,会完整替换当前构建。两个渠道共用设置,安装前会先保存一份当前设置的快照。", + "desktop.updates.dialog.current": "当前版本 {version} · {channel}", + "desktop.updates.dialog.download": "下载并安装", + "desktop.updates.dialog.downloads": "打开下载页面", + "desktop.updates.dialog.fullNotes": "在 GitHub 查看完整说明", + "desktop.updates.dialog.later": "稍后", + "desktop.updates.dialog.noNotes": "这个版本没有附带更新说明。", + "desktop.updates.dialog.notesLoading": "正在读取更新内容…", + "desktop.updates.dialog.restart": "重启并更新", + "desktop.updates.dialog.sizeDelta": "增量更新 {size}(完整安装包 {full})", + "desktop.updates.dialog.sizeFull": "完整安装包 {size}", + "desktop.updates.dialog.skip": "跳过此版本", + "desktop.updates.dialog.title": "Lithe {version} 可更新", + "desktop.updates.manual.managed": "这份 Lithe 由软件包管理器安装,请用它更新,或从下载页面安装新版本。", + "desktop.updates.manual.notWritable": "Lithe 无权替换当前位置的应用,请从下载页面安装新版本。", + "desktop.updates.viewChanges": "查看更新内容", "desktop.vcs.commitDirectly": "提交会立即发送到仓库,没有单独的推送步骤。", "desktop.viewer.binaryHint": "此文件不是文本。以下以十六进制只读显示其开头部分。", "desktop.viewer.close": "关闭", diff --git a/desktop/internal/settingswindow/controller.go b/desktop/internal/settingswindow/controller.go index 85bd3a3a1b..81dc3d0a19 100644 --- a/desktop/internal/settingswindow/controller.go +++ b/desktop/internal/settingswindow/controller.go @@ -412,6 +412,16 @@ type Options struct { UpdateNow func() CancelUpdate func() SetAutoCheckUpdates func(bool) + // SetUpdateChannel switches the channel updates come from, as setUpdateChannel takes it: + // now picks stable's latest release at once on the way back from AutoBuild, and restore + // brings back the settings saved when Lithe last left the channel. SetUpdateSource sets a + // channel's feed, an empty address putting it back on the default. ShowUpdate opens the + // update dialog on the workbench window and brings that window forward; SkipUpdate skips + // the available version. None of them waits. + SetUpdateChannel func(channel string, now, restore bool) + SetUpdateSource func(channel, url string) + ShowUpdate func() + SkipUpdate func() // OpenURL opens an HTTPS page in the system browser. OpenURL func(string) // SetHideProjectColors hands a change of Values.HideProjectColors to the settings diff --git a/desktop/internal/settingswindow/updates_view.go b/desktop/internal/settingswindow/updates_view.go index c78f5b5dbf..ca95c459b5 100644 --- a/desktop/internal/settingswindow/updates_view.go +++ b/desktop/internal/settingswindow/updates_view.go @@ -1,7 +1,9 @@ package settingswindow import ( + "net/url" "strconv" + "strings" "time" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" @@ -11,13 +13,41 @@ import ( // UpdateStatus is what the updater is doing, as the update card shows it. The settings // owner keeps it and the card reads it on every paint. type UpdateStatus struct { - // Configured is false for a build that has no update feed. + // Configured is false for a build that cannot check: a local build, or a packaged one + // without the keys its feeds are signed with. Local says it is a local build, which has no + // channel. Configured bool - Checking bool + Local bool + // Installed is the channel the build was packaged for, and Channel the one it updates + // from, which the user may have switched to; Sources is the feed of each channel. + Installed string + Channel string + Sources []UpdateSource + // Waiting is the release AutoBuild waits to go past on its way back to stable: stable + // offers a version only once one is newer than it. Empty unless the user switched to + // stable from AutoBuild to wait. + Waiting string + // Restorable are the channels whose settings were kept when Lithe last left them, which + // switching back can restore. + Restorable []string + // BuildTime and Commit say when and from what the build was packaged. + BuildTime, Commit string + Checking bool // Available is the newer version the feed offers, empty when none; NotesURL its // release notes. Available string NotesURL string + // Cross says Available is on another channel than the installed one: it replaces the + // build in full. Skipped says the user skipped it, so only a check they ask for shows it. + Cross bool + Skipped bool + // Notes are the release notes of Available, Markdown, empty when the feed has none for + // it; NotesLoading says they are still on the way. + Notes string + NotesLoading bool + // Manual is why the installation cannot replace itself, which an install found: the + // version has to be downloaded by hand. + Manual string // UpToDate says the last check found nothing newer. UpToDate bool // Delta says Update downloads the patch from the running version, DeltaSize bytes, @@ -41,6 +71,21 @@ type UpdateStatus struct { LastChecked time.Time } +// UpdateSource is the feed one channel reads: URL, which Custom says the user set instead of +// the channel's default. +type UpdateSource struct { + Channel string + URL string + Custom bool +} + +// ValidUpdateSource says text can be a feed address: an absolute HTTPS URL with a host, which +// is all the updater accepts. +func ValidUpdateSource(text string) bool { + parsed, err := url.Parse(strings.TrimSpace(text)) + return err == nil && parsed.Scheme == "https" && parsed.Host != "" && parsed.User == nil +} + // updatesPage is the Updates page of Appearance & Behavior: the running version over the // update card the About page shows too. func (w *window) updatesPage(c ui.C) { diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index b0cc4dc7f7..5042352d12 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -346,6 +346,18 @@ type settings struct { // Both are the window's (updater.store, updates.go). UpdatesManual bool `json:"updatesManual,omitempty"` UpdatesCheckedAt time.Time `json:"updatesCheckedAt,omitzero"` + // UpdateChannel is the channel the user chose to update from when it is not the one the + // build was packaged for; empty follows the build. UpdateSources are the feeds the user set + // in place of a channel's default, and UpdateSkipped the version the user skipped, both by + // channel. UpdateReturnNow and UpdateRestore are what the user chose with UpdateChannel: + // stable's latest release at once on the way back from AutoBuild rather than the first one + // past the build, and the settings kept when Lithe last left the channel brought back once + // its release is installed. All are the window's (updater.store, updates.go). + UpdateChannel string `json:"updateChannel,omitempty"` + UpdateReturnNow bool `json:"updateReturnNow,omitempty"` + UpdateRestore bool `json:"updateRestore,omitempty"` + UpdateSources map[string]string `json:"updateSources,omitempty"` + UpdateSkipped map[string]string `json:"updateSkipped,omitempty"` // Network is the proxy settings of the application's own HTTP traffic (network.go). Network settingswindow.NetworkSettings `json:"network,omitzero"` // LocalHistory is which files local history leaves out and how much of it a project keeps @@ -734,7 +746,12 @@ func New(options Options) *App { } a.gitConsole = core.NewGitConsole(a.gitConsoleChanged) // The settings are read before the log sink is in place; a failure is recorded below, once - // it is. + // it is. The first window first restores the settings an update to another channel asked + // to bring back (update_snapshots.go). + var restoreErr error + if options.first == nil { + _, restoreErr = restorePendingSettings(a.store, buildinfo.InstalledChannel(), options.Version) + } _, settingsErr := a.store.Load(settingsFile, &a.settings) if settingsErr != nil { a.settings = settings{} @@ -795,6 +812,9 @@ func New(options Options) *App { if settingsErr != nil { a.storedStateFailed("settings", settingsErr) } + if restoreErr != nil { + a.backgroundFailed("update_snapshot", restoreErr) + } a.openPlugins(options) a.settingsWindow = a.newSettingsWindow() a.loadRecent() diff --git a/desktop/internal/workbench/notifications.go b/desktop/internal/workbench/notifications.go index 7524e00bb6..1482ac3283 100644 --- a/desktop/internal/workbench/notifications.go +++ b/desktop/internal/workbench/notifications.go @@ -38,6 +38,10 @@ type notification struct { // during one. The toast and the history offer View Logs for it, which opens the log window // on that action's records. op string + // act is what the notice's own button does, labeled actLabel, nil for a notice without + // one; it runs on the workbench the notice is on. A notice with act offers no View Logs. + act func(*App) + actLabel string } // notificationCenter owns the history shared by the tool window and the status popover. @@ -100,6 +104,12 @@ func (a *App) notificationColor(kind ui.ToastKind) gfx.Color { // and its toast shows the count, replacing the toast it had. A failure reported during a user // action refers to the action's records: its toast has a View Logs button. func (a *App) notifyKind(message string, kind ui.ToastKind) { + a.notifyAction(message, kind, "", nil) +} + +// notifyAction is notifyKind with a button of the notice's own, label, which runs act. A +// repeat of the notice keeps the latest button. +func (a *App) notifyAction(message string, kind ui.ToastKind, label string, act func(*App)) { a.notice = message center := &a.notifications var entry *notification @@ -116,6 +126,7 @@ func (a *App) notifyKind(message string, kind ui.ToastKind) { } entry.count++ entry.at = a.now() + entry.act, entry.actLabel = act, label entry.unread = !center.open if kind == ui.ToastError && a.op.id != "" { entry.op = a.op.id @@ -125,7 +136,10 @@ func (a *App) notifyKind(message string, kind ui.ToastKind) { center.list = center.list[:notificationHistoryLimit] } action := "" - if a.viewsLogs(entry) { + switch { + case entry.act != nil: + action = entry.actLabel + case a.viewsLogs(entry): action = i18n.Shared(a.language(), "desktop.notifications.viewLogs") } entry.toast = a.overlay.toaster.ShowAction(a.notificationText(entry), "", kind, action) @@ -138,17 +152,22 @@ func (a *App) notifyKind(message string, kind ui.ToastKind) { // viewsLogs says the notice offers View Logs: it refers to an action's records and there is a // log window to show them in. func (a *App) viewsLogs(entry *notification) bool { - return entry.op != "" && a.logs != nil + return entry.act == nil && entry.op != "" && a.logs != nil } -// notificationActed opens the records of the notice whose toast's View Logs this paint -// delivered a press on. Call it after ui.Toasts. +// notificationActed runs the button of the notice whose toast this paint delivered a press on: +// its own, or View Logs, which opens its records. Call it after ui.Toasts. func (a *App) notificationActed(c ui.C) { id, ok := a.overlay.toaster.Acted() if !ok { return } for _, entry := range a.notifications.list { + if entry.toast == id && entry.act != nil { + act := entry.act + c.After(func() { a.notificationAct(act) }) + return + } if entry.toast == id && entry.op != "" { op := entry.op c.After(func() { a.viewNotificationLogs(op) }) @@ -164,6 +183,12 @@ func (a *App) viewNotificationLogs(op string) { a.showLogs(op) } +// notificationAct runs a notice's own button, which closes the history it may be pressed in. +func (a *App) notificationAct(act func(*App)) { + a.notifications.open = false + act(a) +} + // notificationText is a notice's words, with how often it came when that is more than once. func (a *App) notificationText(entry *notification) string { if entry.count < 2 { @@ -294,6 +319,10 @@ func (a *App) notificationEntry(k ui.C, entry *notification) { } ui.Row(k).FillWidth().Items(ui.Center).Gap(8).Children(func() { ui.Text(k, meta).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Grow(1).Ellipsis() + if entry.act != nil && ui.Button(k.Part("act"), entry.actLabel).Ghost().Small().Clicked() { + act := entry.act + k.After(func() { a.notificationAct(act) }) + } if a.viewsLogs(entry) && ui.Button(k.Part("logs"), i18n.Shared(language, "desktop.notifications.viewLogs")).Ghost().Small().Clicked() { op := entry.op k.After(func() { a.viewNotificationLogs(op) }) diff --git a/desktop/internal/workbench/settings.go b/desktop/internal/workbench/settings.go index 6616e4a896..e42719570f 100644 --- a/desktop/internal/workbench/settings.go +++ b/desktop/internal/workbench/settings.go @@ -260,7 +260,13 @@ func (a *App) newSettingsWindow() *settingswindow.Controller { UpdateNow: func() { a.post(func(a *App) { a.updateNow() }) }, CancelUpdate: func() { a.post(func(a *App) { a.cancelUpdate() }) }, SetAutoCheckUpdates: func(on bool) { a.post(func(a *App) { a.setAutoCheckUpdates(on) }) }, - OpenURL: func(address string) { a.post(func(a *App) { a.openSettingsLink(address) }) }, + SetUpdateChannel: func(channel string, now, restore bool) { + a.post(func(a *App) { a.setUpdateChannel(channel, now, restore) }) + }, + SetUpdateSource: func(channel, url string) { a.post(func(a *App) { a.setUpdateSource(channel, url) }) }, + ShowUpdate: func() { a.post(func(a *App) { a.showUpdateDialog(surfaceButton) }) }, + SkipUpdate: func() { a.post(func(a *App) { a.skipUpdate() }) }, + OpenURL: func(address string) { a.post(func(a *App) { a.openSettingsLink(address) }) }, SetNetwork: func(next settingswindow.NetworkSettings, password *string) { a.post(func(a *App) { a.setNetwork(next, password) }) }, diff --git a/desktop/internal/workbench/update_channels.go b/desktop/internal/workbench/update_channels.go new file mode 100644 index 0000000000..1a2e57fda1 --- /dev/null +++ b/desktop/internal/workbench/update_channels.go @@ -0,0 +1,252 @@ +package workbench + +import ( + "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/buildinfo" + "github.com/1lck/Lithe-IDEA/desktop/internal/settingswindow" + "github.com/vivaui/viva/app" + appupdate "github.com/vivaui/viva/update" +) + +// A build updates from the channel it was packaged for (buildinfo.InstalledChannel) until the +// user switches to the other in Settings > Updates; the choice is saved (settings.UpdateChannel) +// and a build of the chosen channel, once installed, follows its own channel again. The two +// channels' versions are never compared with each other: an AutoBuild version is the release +// it builds towards with a pre-release suffix, 0.7.0-autobuild.