diff --git a/src-tauri/src/updater.rs b/src-tauri/src/updater.rs index e0d8d971..c148291a 100644 --- a/src-tauri/src/updater.rs +++ b/src-tauri/src/updater.rs @@ -54,6 +54,7 @@ pub async fn set_update_check(app: tauri::AppHandle, on: bool) -> Out, } /// 更新在内存里的那点状态。 @@ -69,6 +70,7 @@ pub struct Updates { #[derive(serde::Serialize)] pub struct OfferView { version: String, + notes: Option, current: String, install: update::Install, /// Homebrew 那一档要执行的命令。**由这里给出,界面上不再写一遍** —— @@ -78,11 +80,12 @@ pub struct OfferView { /// 读发布页上的清单:最新的那一版比现在新吗。 /// -/// 读的是一份几百字节的 JSON,不下载任何别的东西。 -pub(crate) async fn look(app: &tauri::AppHandle) -> Result, String> { +/// 只读清单,不下载安装包。 +async fn look(app: &tauri::AppHandle) -> Result, String> { let found = updater(app)?.check().await.map_err(|e| e.to_string())?; Ok(found.map(|up| Found { - version: up.version.clone(), + version: up.version, + notes: up.body, })) } @@ -155,9 +158,22 @@ async fn ask(app: &tauri::AppHandle) -> Result, String> { if !update::newer(version, ¤t) { return Ok(None); } - Ok(Some(Found { + // 发布说明是附带信息:取不到时仍提示用户更新。只等一小会儿,以免拖慢检查。 + let release = tokio::time::timeout(std::time::Duration::from_secs(3), look(app)) + .await + .ok() + .and_then(Result::ok) + .flatten(); + Ok(Some(brew_offer(version, release))) +} + +fn brew_offer(version: &str, release: Option) -> Found { + Found { version: version.to_string(), - })) + notes: release + .filter(|r| r.version == version) + .and_then(|r| r.notes), + } } pub(crate) const UPDATE_WINDOW: &str = "update"; @@ -368,6 +384,7 @@ pub fn update_pending(app: tauri::AppHandle) -> Option { let install = update::kind(); Some(OfferView { version: found.version, + notes: found.notes, current: app.package_info().version.to_string(), install, command: (install == update::Install::Homebrew).then_some(update::BREW_UPGRADE), @@ -962,6 +979,24 @@ mod tests { use crate::i18n::{Lang, with_lang}; use notices::Mode; + #[test] + fn brew_uses_notes_only_for_the_version_in_the_cask() { + let release = Found { + version: "2026.11.20".into(), + notes: Some("Release notes".into()), + }; + let matching = brew_offer("2026.11.20", Some(release.clone())); + assert_eq!(matching.notes.as_deref(), Some("Release notes")); + + let behind = brew_offer("2026.11.19", Some(release)); + assert_eq!(behind.version, "2026.11.19"); + assert_eq!(behind.notes, None); + + let unavailable = brew_offer("2026.11.20", None); + assert_eq!(unavailable.version, "2026.11.20"); + assert_eq!(unavailable.notes, None); + } + /// 「已更新到 x」和别的告知同一个开关:**只在「系统通知」那一档弹** #[test] fn the_updated_notice_follows_the_notification_setting() { diff --git a/src/Update.i18n.ts b/src/Update.i18n.ts index cea65ab7..47c86f2c 100644 --- a/src/Update.i18n.ts +++ b/src/Update.i18n.ts @@ -9,6 +9,7 @@ export const updateText = messages( // 更新窗口 current: (version: string) => `当前版本 ${version}`, available: (version: string) => `ThinkWatch Lite ${version} 可用`, + whatsNew: "本次更新", closeWhileWaiting: "关闭此窗口不影响更新,更新完成后将发送通知。", /** 能在窗口里直接装的那几档(网页下载的、Windows 的绿色版)都是这一句 */ standalone: "下载完成后自动安装并重新启动,进行中的请求不会中断。", @@ -32,6 +33,7 @@ export const updateText = messages( { current: (version: string) => `Current version: ${version}`, available: (version: string) => `ThinkWatch Lite ${version} is available`, + whatsNew: "What's new", closeWhileWaiting: "Closing this window does not stop the update. A notification is sent when it is complete.", standalone: "Installs and restarts automatically after downloading. Requests in progress are not interrupted.", diff --git a/src/UpdateWindow.tsx b/src/UpdateWindow.tsx index b2a1da67..35a7be29 100644 --- a/src/UpdateWindow.tsx +++ b/src/UpdateWindow.tsx @@ -10,6 +10,7 @@ import { Meter } from "@/ui/meter"; import { Spinner } from "@/ui/spinner"; import { StatusDot } from "@/ui/status-dot"; import { IconCopied, IconCopy } from "@/ui/icons"; +import { Markdown } from "@/traffic/Markdown"; import { useText } from "@/i18n"; import { commonText } from "@/i18n/common.i18n"; import { canInstall, describeStep, type Offer, type Step } from "./updateFlow"; @@ -26,7 +27,7 @@ const COPIED_MS = 2_000; * 点了自动检查发出的那条通知、菜单里的「安装新版本」。窗口建出来时是隐藏的 —— 这里 * 画好、量出高度之后再亮出来。 * - * 上面是应用图标、哪一版可用、现在是哪一版;下面画哪一种取决于这一份是怎么装上来的: + * 上面是应用图标、哪一版可用、现在是哪一版、本次更新;下面画哪一种取决于这一份是怎么装上来的: * * · 从网页下载的:「下载并安装」,按一次之后不再问任何问题 —— 下载、 * 等网关手上的请求结束、替换、重启,全部自动。 @@ -93,6 +94,8 @@ export default function UpdateWindow() { void invoke("update_fit", { height }).then(async () => { if (shown.current) return; shown.current = true; + // 先把焦点落在窗口正文。WebKit 激活窗口时就不会选中更新说明或按钮。 + el.focus({ preventScroll: true }); await w.show(); await w.setFocus(); }); @@ -116,6 +119,7 @@ export default function UpdateWindow() { if (!offer) return null; const busy = step !== null && failed === null; + const notes = busy ? null : offer.notes?.trim(); const install = async () => { setFailed(null); @@ -217,7 +221,7 @@ export default function UpdateWindow() { return (
-
+
{/* 应用图标本身(和程序坞里同一张) */} @@ -226,6 +230,21 @@ export default function UpdateWindow() {

{t.current(offer.current)}

+ {notes && ( +
+

+ {t.whatsNew} +

+
+ +
+
+ )} {content} {actions &&
{actions}
}
diff --git a/src/traffic/Markdown.tsx b/src/traffic/Markdown.tsx index 6d65fe8e..4a259c50 100644 --- a/src/traffic/Markdown.tsx +++ b/src/traffic/Markdown.tsx @@ -13,10 +13,10 @@ import { useMarker } from "@/security/Highlight"; * - 链接只显示文字、悬停看地址,不能点:点了会把应用的窗口导航走;图片只显示替代文字 * - 顶层每一块按原文 `memo`:回答在长时只有最后一块重画 */ -export function Markdown({ text, tail }: { text: string; tail?: ReactNode }) { +export function Markdown({ text, tail, className }: { text: string; tail?: ReactNode; className?: string }) { const blocks = useMemo(() => lexer(text, { gfm: true, breaks: true }).filter((b) => b.type !== "space"), [text]); return ( -
+
{blocks.map((b, i) => { const last = i === blocks.length - 1; return ; diff --git a/src/updateFlow.ts b/src/updateFlow.ts index 896624b1..4918964a 100644 --- a/src/updateFlow.ts +++ b/src/updateFlow.ts @@ -18,6 +18,7 @@ export type Install = "homebrew" | "standalone" | "portable" | "dev"; /** 查到的新版本。 */ export interface Found { version: string; + notes?: string | null; } /** 设置页读的那份状态。 */ @@ -29,8 +30,7 @@ export interface UpdateView { } /** 更新窗口要画的东西。 */ -export interface Offer { - version: string; +export interface Offer extends Found { current: string; install: Install; /** Homebrew 那一档要执行的命令。由 Rust 给出,界面上不再写一遍 */