diff --git a/src/renderer/src/hooks/useAppInit.ts b/src/renderer/src/hooks/useAppInit.ts index e9e3b55706..763eff87da 100644 --- a/src/renderer/src/hooks/useAppInit.ts +++ b/src/renderer/src/hooks/useAppInit.ts @@ -76,14 +76,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(() => {