feat(useAppInit): implement automatic update checks with interval sup… (#11063)

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.
This commit is contained in:
亢奋猫 2025-10-31 13:35:27 +08:00 committed by kangfenmao
parent daecac80fa
commit ce5829c24d

View File

@ -76,14 +76,31 @@ export function useAppInit() {
}, [avatar, dispatch]) }, [avatar, dispatch])
useEffect(() => { 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 () => { runAsyncFunction(async () => {
const { isPackaged } = await window.api.getAppInfo() const { isPackaged } = await window.api.getAppInfo()
if (isPackaged && autoCheckUpdate) { if (isPackaged && autoCheckUpdate) {
await delay(2) await delay(2)
const { updateInfo } = await window.api.checkForUpdate() await checkForUpdates()
dispatch(setUpdateState({ info: updateInfo }))
} }
}) })
// Set up 4-hour interval check
const FOUR_HOURS = 4 * 60 * 60 * 1000
const intervalId = setInterval(checkForUpdates, FOUR_HOURS)
return () => clearInterval(intervalId)
}, [dispatch, autoCheckUpdate]) }, [dispatch, autoCheckUpdate])
useEffect(() => { useEffect(() => {