From d195bb9f1bb036654fb237f21c036976827c39c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B1=BC=E5=BC=80=E5=8F=91?= Date: Mon, 1 Jun 2026 16:51:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=AF=8F=E5=A4=A9=E6=A3=80=E6=9F=A5=E4=B8=80?= =?UTF-8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 localStorage 记录上次检查时间戳 (mjk_last_update_check) - 启动时判断距离上次检查是否超过 24 小时 - 未超过则跳过,避免每次启动都请求后端 - 设置页手动检查不受此限制 --- .../components/UpdateDialog/UpdateDialog.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tauri-app/src/components/UpdateDialog/UpdateDialog.tsx b/tauri-app/src/components/UpdateDialog/UpdateDialog.tsx index 71ebb5b..60ed93a 100644 --- a/tauri-app/src/components/UpdateDialog/UpdateDialog.tsx +++ b/tauri-app/src/components/UpdateDialog/UpdateDialog.tsx @@ -2,7 +2,7 @@ * 更新对话框组件 * ============== * - * 应用启动时自动检查更新,发现新版本后弹出此对话框。 + * 应用启动时自动检查更新(每天最多一次),发现新版本后弹出此对话框。 * 支持强制更新(无法跳过)。 */ @@ -30,11 +30,22 @@ export default function UpdateDialog() { relaunch, } = useUpdater(); - // 应用启动时自动检查更新(延迟 3 秒,避免阻塞首屏) - // silent=true:失败时不弹窗,只打 console 日志 + // 应用启动时自动检查更新(每天最多一次) + // 延迟 3 秒避免阻塞首屏;silent=true:失败时不弹窗,只打 console 日志 useEffect(() => { const timer = setTimeout(() => { - check(true); + const LAST_CHECK_KEY = 'mjk_last_update_check'; + const ONE_DAY_MS = 24 * 60 * 60 * 1000; + + const lastCheckRaw = localStorage.getItem(LAST_CHECK_KEY); + const lastCheck = lastCheckRaw ? parseInt(lastCheckRaw, 10) : 0; + const now = Date.now(); + + if (!lastCheck || now - lastCheck > ONE_DAY_MS) { + check(true).finally(() => { + localStorage.setItem(LAST_CHECK_KEY, Date.now().toString()); + }); + } }, 3000); return () => clearTimeout(timer); }, [check]);