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]);