Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src-tauri/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub async fn set_update_check(app: tauri::AppHandle, on: bool) -> Out<UpdateView
#[derive(Clone, serde::Serialize)]
pub struct Found {
version: String,
notes: Option<String>,
}

/// 更新在内存里的那点状态。
Expand All @@ -69,6 +70,7 @@ pub struct Updates {
#[derive(serde::Serialize)]
pub struct OfferView {
version: String,
notes: Option<String>,
current: String,
install: update::Install,
/// Homebrew 那一档要执行的命令。**由这里给出,界面上不再写一遍** ——
Expand All @@ -78,11 +80,12 @@ pub struct OfferView {

/// 读发布页上的清单:最新的那一版比现在新吗。
///
/// 读的是一份几百字节的 JSON,不下载任何别的东西。
pub(crate) async fn look(app: &tauri::AppHandle) -> Result<Option<Found>, String> {
/// 只读清单,不下载安装包。
async fn look(app: &tauri::AppHandle) -> Result<Option<Found>, 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,
}))
}

Expand Down Expand Up @@ -155,9 +158,22 @@ async fn ask(app: &tauri::AppHandle) -> Result<Option<Found>, String> {
if !update::newer(version, &current) {
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 {
Found {
version: version.to_string(),
}))
notes: release
.filter(|r| r.version == version)
.and_then(|r| r.notes),
}
}

pub(crate) const UPDATE_WINDOW: &str = "update";
Expand Down Expand Up @@ -368,6 +384,7 @@ pub fn update_pending(app: tauri::AppHandle) -> Option<OfferView> {
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),
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/Update.i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const updateText = messages(
// 更新窗口
current: (version: string) => `当前版本 ${version}`,
available: (version: string) => `ThinkWatch Lite ${version} 可用`,
whatsNew: "本次更新",
closeWhileWaiting: "关闭此窗口不影响更新,更新完成后将发送通知。",
/** 能在窗口里直接装的那几档(网页下载的、Windows 的绿色版)都是这一句 */
standalone: "下载完成后自动安装并重新启动,进行中的请求不会中断。",
Expand All @@ -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.",
Expand Down
23 changes: 21 additions & 2 deletions src/UpdateWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -26,7 +27,7 @@ const COPIED_MS = 2_000;
* 点了自动检查发出的那条通知、菜单里的「安装新版本」。窗口建出来时是隐藏的 —— 这里
* 画好、量出高度之后再亮出来。
*
* 上面是应用图标、哪一版可用、现在是哪一版;下面画哪一种取决于这一份是怎么装上来的:
* 上面是应用图标、哪一版可用、现在是哪一版、本次更新;下面画哪一种取决于这一份是怎么装上来的:
*
* · 从网页下载的:「下载并安装」,按一次之后不再问任何问题 —— 下载、
* 等网关手上的请求结束、替换、重启,全部自动。
Expand Down Expand Up @@ -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();
});
Expand All @@ -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);
Expand Down Expand Up @@ -217,7 +221,7 @@ export default function UpdateWindow() {

return (
<div className="min-h-screen bg-background text-foreground">
<div ref={body} className="flex flex-col gap-4 p-5">
<div ref={body} tabIndex={-1} className="flex flex-col gap-4 p-5 outline-none">
<header className="flex items-center gap-3.5">
{/* 应用图标本身(和程序坞里同一张) */}
<img src={appIcon} alt="" width={48} height={48} draggable={false} className="size-12 shrink-0 select-none" />
Expand All @@ -226,6 +230,21 @@ export default function UpdateWindow() {
<p className="tw-num tw-body text-muted-foreground">{t.current(offer.current)}</p>
</div>
</header>
{notes && (
<section className="flex min-w-0 flex-col gap-1.5">
<h2 id="update-notes-title" className="tw-label text-muted-foreground">
{t.whatsNew}
</h2>
<div
role="region"
aria-labelledby="update-notes-title"
tabIndex={0}
className="tw-body max-h-40 overflow-x-hidden overflow-y-auto overscroll-contain select-text focus-visible:outline-2 focus-visible:outline-ring"
>
<Markdown text={notes} className="wrap-anywhere [&_pre]:whitespace-pre-wrap" />
</div>
</section>
)}
{content}
{actions && <div className="flex justify-end gap-2">{actions}</div>}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/traffic/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="flex flex-col gap-2 wrap-break-word">
<div className={cn("flex flex-col gap-2 wrap-break-word", className)}>
{blocks.map((b, i) => {
const last = i === blocks.length - 1;
return <Block key={i} token={b} raw={b.raw} tail={last ? tail : undefined} />;
Expand Down
4 changes: 2 additions & 2 deletions src/updateFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Install = "homebrew" | "standalone" | "portable" | "dev";
/** 查到的新版本。 */
export interface Found {
version: string;
notes?: string | null;
}

/** 设置页读的那份状态。 */
Expand All @@ -29,8 +30,7 @@ export interface UpdateView {
}

/** 更新窗口要画的东西。 */
export interface Offer {
version: string;
export interface Offer extends Found {
current: string;
install: Install;
/** Homebrew 那一档要执行的命令。由 Rust 给出,界面上不再写一遍 */
Expand Down
Loading