From ce2f09d29e917711c83f9af9f3011b1bfedd5893 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Tue, 27 Jan 2026 13:18:33 -0800 Subject: [PATCH] Refactor useAutoUpdater hook for improved readability and update handling - Rearranged import statements for better organization. - Enhanced download progress handling logic for clarity and consistency. - Ensured proper state updates during the download process, including setting download progress to 100% upon completion. --- app/src/hooks/useAutoUpdater.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/hooks/useAutoUpdater.ts b/app/src/hooks/useAutoUpdater.ts index 7f3b9b41..f6d7584f 100644 --- a/app/src/hooks/useAutoUpdater.ts +++ b/app/src/hooks/useAutoUpdater.ts @@ -1,6 +1,6 @@ -import { useCallback, useEffect, useState } from 'react'; -import { check, type Update } from '@tauri-apps/plugin-updater'; import { relaunch } from '@tauri-apps/plugin-process'; +import { check, type Update } from '@tauri-apps/plugin-updater'; +import { useCallback, useEffect, useState } from 'react'; export interface UpdateStatus { checking: boolean; @@ -92,23 +92,22 @@ export function useAutoUpdater(checkOnMount = false) { case 'Started': totalBytes = event.data.contentLength || 0; downloadedBytes = 0; - setStatus((prev) => ({ - ...prev, + setStatus((prev) => ({ + ...prev, downloading: true, totalBytes, downloadedBytes: 0, - downloadProgress: 0 + downloadProgress: 0, })); break; case 'Progress': { downloadedBytes += event.data.chunkLength; - const progress = totalBytes > 0 - ? Math.round((downloadedBytes / totalBytes) * 100) - : undefined; + const progress = + totalBytes > 0 ? Math.round((downloadedBytes / totalBytes) * 100) : undefined; setStatus((prev) => ({ ...prev, downloadedBytes, - downloadProgress: progress + downloadProgress: progress, })); break; } @@ -117,7 +116,7 @@ export function useAutoUpdater(checkOnMount = false) { ...prev, downloading: false, readyToInstall: true, - downloadProgress: 100 + downloadProgress: 100, })); break; }