From c597b9b1221a482425ee1067cbe57f46b7d2ccfd Mon Sep 17 00:00:00 2001 From: farion1231 Date: Thu, 11 Sep 2025 15:13:33 +0800 Subject: [PATCH] feat(ui): add "up-to-date" feedback for update check button - Show green "Already up-to-date" state with check icon when no updates available - Button changes color and text temporarily (3 seconds) to provide clear feedback - Fix TypeScript type for checkUpdate to return Promise - Handle dev mode gracefully - show up-to-date instead of opening release page - Simplify previous complex notification UI to inline button state change --- src/components/SettingsModal.tsx | 63 ++++++++++++++++++++++++++------ src/contexts/UpdateContext.tsx | 7 +++- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsx index 95cf8ac..3a2a6dc 100644 --- a/src/components/SettingsModal.tsx +++ b/src/components/SettingsModal.tsx @@ -1,5 +1,12 @@ import { useState, useEffect } from "react"; -import { X, RefreshCw, FolderOpen, Download, ExternalLink } from "lucide-react"; +import { + X, + RefreshCw, + FolderOpen, + Download, + ExternalLink, + Check, +} from "lucide-react"; import { getVersion } from "@tauri-apps/api/app"; import "../lib/tauri-api"; import { relaunchApp } from "../lib/updater"; @@ -18,7 +25,9 @@ export default function SettingsModal({ onClose }: SettingsModalProps) { const [version, setVersion] = useState(""); const [isCheckingUpdate, setIsCheckingUpdate] = useState(false); const [isDownloading, setIsDownloading] = useState(false); - const { hasUpdate, updateInfo, updateHandle, checkUpdate, resetDismiss } = useUpdate(); + const [showUpToDate, setShowUpToDate] = useState(false); + const { hasUpdate, updateInfo, updateHandle, checkUpdate, resetDismiss } = + useUpdate(); useEffect(() => { loadSettings(); @@ -86,12 +95,29 @@ export default function SettingsModal({ onClose }: SettingsModalProps) { } else { // 尚未检测到更新:先检查 setIsCheckingUpdate(true); + setShowUpToDate(false); try { - await checkUpdate(); - // 检查后若有更新,让用户再次点击执行 + const hasNewUpdate = await checkUpdate(); + // 检查完成后,如果没有更新,显示"已是最新" + if (!hasNewUpdate) { + setShowUpToDate(true); + // 3秒后恢复按钮文字 + setTimeout(() => { + setShowUpToDate(false); + }, 3000); + } } catch (error) { - console.error("检查更新失败,回退到 Releases 页面:", error); - await window.api.checkForUpdates(); + console.error("检查更新失败:", error); + // 在开发模式下,模拟已是最新版本的响应 + if (import.meta.env.DEV) { + setShowUpToDate(true); + setTimeout(() => { + setShowUpToDate(false); + }, 3000); + } else { + // 生产环境下如果更新插件不可用,回退到打开 Releases 页面 + await window.api.checkForUpdates(); + } } finally { setIsCheckingUpdate(false); } @@ -111,12 +137,16 @@ export default function SettingsModal({ onClose }: SettingsModalProps) { const targetVersion = updateInfo?.availableVersion || version; // 如果未知或为空,回退到 releases 首页 if (!targetVersion || targetVersion === "未知") { - await window.api.openExternal("https://github.com/farion1231/cc-switch/releases"); + await window.api.openExternal( + "https://github.com/farion1231/cc-switch/releases" + ); return; } - const tag = targetVersion.startsWith("v") ? targetVersion : `v${targetVersion}`; + const tag = targetVersion.startsWith("v") + ? targetVersion + : `v${targetVersion}`; await window.api.openExternal( - `https://github.com/farion1231/cc-switch/releases/tag/${tag}`, + `https://github.com/farion1231/cc-switch/releases/tag/${tag}` ); } catch (error) { console.error("打开更新日志失败:", error); @@ -206,7 +236,9 @@ export default function SettingsModal({ onClose }: SettingsModalProps) {