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 GitHub
parent aa810a7ead
commit f8a599322f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(() => {