From 89c60aa649d62063fc7a9d0db032ddae8a55c9ab Mon Sep 17 00:00:00 2001 From: thecodrr Date: Wed, 29 Sep 2021 14:08:32 +0500 Subject: [PATCH] fix: clear timeout on any update status change --- apps/web/src/hooks/use-auto-updater.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/web/src/hooks/use-auto-updater.js b/apps/web/src/hooks/use-auto-updater.js index 33af349e4..e332768a5 100644 --- a/apps/web/src/hooks/use-auto-updater.js +++ b/apps/web/src/hooks/use-auto-updater.js @@ -9,29 +9,32 @@ export default function useAutoUpdater() { const [status, setStatus] = useState(); useEffect(() => { - function checkingForUpdate() { - setStatus({ type: "checking" }); - + function changeStatus(status) { clearTimeout(checkingForUpdateTimeout); + setStatus(status); + } + + function checkingForUpdate() { + changeStatus({ type: "checking" }); checkingForUpdateTimeout = setTimeout(() => { - setStatus({ type: "updated" }); + changeStatus({ type: "updated" }); }, 10000); } function updateAvailable(info) { - setStatus({ type: "available", version: info.version }); + changeStatus({ type: "available", version: info.version }); } function updateNotAvailable(info) { - setStatus({ type: "updated" }); + changeStatus({ type: "updated" }); } function updateDownloadCompleted(info) { - setStatus({ type: "completed", version: info.version }); + changeStatus({ type: "completed", version: info.version }); } function updateDownloadProgress(progressInfo) { - setStatus({ type: "downloading", progress: progressInfo.percent }); + changeStatus({ type: "downloading", progress: progressInfo.percent }); } ElectronEventManager.subscribe(EVENTS.checkingForUpdate, checkingForUpdate);