feat: add update indicators and stabilize Cursor streams

This commit is contained in:
leookun
2026-08-24 05:24:07 +08:00
parent 0f23a9a9c3
commit 6170778de9
21 changed files with 360 additions and 105 deletions
@@ -21,3 +21,11 @@
font-size: type.$font-size-xs;
}
}
.updateDot {
width: 7px;
height: 7px;
flex: 0 0 7px;
background: #ef4444;
border-radius: 50%;
}
@@ -1,13 +1,11 @@
import { useEffect, useRef, useState } from "react";
import type { Update } from "@tauri-apps/plugin-updater";
import { useEffect, useState } from "react";
import {
checkForUpdate,
currentAppVersion,
hasNativeAppLifecycle,
installUpdate,
readAutostart,
writeAutostart,
} from "../../native/appLifecycle";
import { updateStore, useUpdateStore } from "../../store/updateStore";
import { Button } from "../ui/Button";
import { Switch } from "../ui/Switch";
import { TitledCard } from "../ui/TitledCard";
@@ -17,13 +15,10 @@ import styles from "./AppLifecycleSettingsCard.module.scss";
export function AppLifecycleSettingsCard() {
const message = useMessage();
const native = hasNativeAppLifecycle();
const updateRef = useRef<Update | null>(null);
const { availableVersion, checking, installing } = useUpdateStore();
const [version, setVersion] = useState("…");
const [autostart, setAutostart] = useState(false);
const [loadingAutostart, setLoadingAutostart] = useState(native);
const [checking, setChecking] = useState(false);
const [installing, setInstalling] = useState(false);
const [availableVersion, setAvailableVersion] = useState<string | null>(null);
useEffect(() => {
let disposed = false;
@@ -34,12 +29,7 @@ export function AppLifecycleSettingsCard() {
.catch((cause) => message(cause instanceof Error ? cause.message : String(cause)))
.finally(() => { if (!disposed) setLoadingAutostart(false); });
}
return () => {
disposed = true;
const update = updateRef.current;
updateRef.current = null;
if (update) void update.close();
};
return () => { disposed = true; };
}, [message, native]);
const toggleAutostart = async (enabled: boolean) => {
@@ -57,29 +47,17 @@ export function AppLifecycleSettingsCard() {
const checkUpdate = async () => {
try {
setChecking(true);
const previous = updateRef.current;
updateRef.current = null;
if (previous) await previous.close();
const update = await checkForUpdate();
updateRef.current = update;
setAvailableVersion(update?.version ?? null);
message(update ? t("发现新版本 {version}", { version: update.version }) : t("当前已是最新版本"));
const nextVersion = await updateStore.check();
message(nextVersion ? t("发现新版本 {version}", { version: nextVersion }) : t("当前已是最新版本"));
} catch (cause) {
message(cause instanceof Error ? cause.message : String(cause));
} finally {
setChecking(false);
}
};
const updateNow = async () => {
const update = updateRef.current;
if (!update) return;
try {
setInstalling(true);
await installUpdate(update);
await updateStore.install();
} catch (cause) {
setInstalling(false);
message(cause instanceof Error ? cause.message : String(cause));
}
};
@@ -107,6 +85,7 @@ export function AppLifecycleSettingsCard() {
{availableVersion
? <Button size="small" variant="primary" disabled={installing} onClick={() => void updateNow()}>
{installing ? t("安装中…") : t("下载并安装")}
<span className={styles.updateDot} aria-hidden="true" />
</Button>
: <Button size="small" disabled={!native || checking} onClick={() => void checkUpdate()}>
{checking ? t("检查中…") : t("检查更新")}