mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 20:12:38 +08:00
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:
parent
aa810a7ead
commit
f8a599322f
@ -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(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user