mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-29 15:15:27 -07:00
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.
This commit is contained in:
@@ -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 { relaunch } from '@tauri-apps/plugin-process';
|
||||||
|
import { check, type Update } from '@tauri-apps/plugin-updater';
|
||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
export interface UpdateStatus {
|
export interface UpdateStatus {
|
||||||
checking: boolean;
|
checking: boolean;
|
||||||
@@ -92,23 +92,22 @@ export function useAutoUpdater(checkOnMount = false) {
|
|||||||
case 'Started':
|
case 'Started':
|
||||||
totalBytes = event.data.contentLength || 0;
|
totalBytes = event.data.contentLength || 0;
|
||||||
downloadedBytes = 0;
|
downloadedBytes = 0;
|
||||||
setStatus((prev) => ({
|
setStatus((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
downloading: true,
|
downloading: true,
|
||||||
totalBytes,
|
totalBytes,
|
||||||
downloadedBytes: 0,
|
downloadedBytes: 0,
|
||||||
downloadProgress: 0
|
downloadProgress: 0,
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
case 'Progress': {
|
case 'Progress': {
|
||||||
downloadedBytes += event.data.chunkLength;
|
downloadedBytes += event.data.chunkLength;
|
||||||
const progress = totalBytes > 0
|
const progress =
|
||||||
? Math.round((downloadedBytes / totalBytes) * 100)
|
totalBytes > 0 ? Math.round((downloadedBytes / totalBytes) * 100) : undefined;
|
||||||
: undefined;
|
|
||||||
setStatus((prev) => ({
|
setStatus((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
downloadedBytes,
|
downloadedBytes,
|
||||||
downloadProgress: progress
|
downloadProgress: progress,
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -117,7 +116,7 @@ export function useAutoUpdater(checkOnMount = false) {
|
|||||||
...prev,
|
...prev,
|
||||||
downloading: false,
|
downloading: false,
|
||||||
readyToInstall: true,
|
readyToInstall: true,
|
||||||
downloadProgress: 100
|
downloadProgress: 100,
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user