From f8a599322f00c56f4d56b742dee1e1acccd6fd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=A2=E5=A5=8B=E7=8C=AB?= Date: Fri, 31 Oct 2025 13:35:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(useAppInit):=20implement=20automatic=20upd?= =?UTF-8?q?ate=20checks=20with=20interval=20sup=E2=80=A6=20(#11063)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(useAppInit): implement automatic update checks with interval support - Added a function to check for updates, which is called initially and set to run every 6 hours if the app is packaged and auto-update is enabled. - Refactored the initial update check to utilize the new function for better code organization and clarity. --- src/renderer/src/hooks/useAppInit.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/hooks/useAppInit.ts b/src/renderer/src/hooks/useAppInit.ts index 28fc6a958c..3ecbdf7621 100644 --- a/src/renderer/src/hooks/useAppInit.ts +++ b/src/renderer/src/hooks/useAppInit.ts @@ -83,14 +83,31 @@ export function useAppInit() { }, [avatar, dispatch]) useEffect(() => { + const checkForUpdates = async () => { + const { isPackaged } = await window.api.getAppInfo() + + if (!isPackaged || !autoCheckUpdate) { + return + } + + const { updateInfo } = await window.api.checkForUpdate() + dispatch(setUpdateState({ info: updateInfo })) + } + + // Initial check with delay runAsyncFunction(async () => { const { isPackaged } = await window.api.getAppInfo() if (isPackaged && autoCheckUpdate) { await delay(2) - const { updateInfo } = await window.api.checkForUpdate() - dispatch(setUpdateState({ info: updateInfo })) + await checkForUpdates() } }) + + // Set up 4-hour interval check + const FOUR_HOURS = 4 * 60 * 60 * 1000 + const intervalId = setInterval(checkForUpdates, FOUR_HOURS) + + return () => clearInterval(intervalId) }, [dispatch, autoCheckUpdate]) useEffect(() => {