Skip to content

Commit

Permalink
Update system progress bar with throttling
Browse files Browse the repository at this point in the history
Signed-off-by: xychen <[email protected]>
  • Loading branch information
xychen committed Jun 14, 2024
1 parent d24e227 commit 8283e03
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import {
import { getCurrent, ProgressBarStatus, UserAttentionType } from '@tauri-apps/api/window';
import { confirm } from '@tauri-apps/plugin-dialog';
import { List16Regular } from '@vicons/fluent';
import { throttle } from 'radash';
import { imageSize, type IFlashImage } from '@/utils/images';
import { cskburn, type ICSKBurnResult } from '@/utils/cskburn';
import { cleanUpTmpFiles } from '@/utils/file';
Expand Down Expand Up @@ -299,6 +300,12 @@ function stopFlash(): void {
aborter?.abort();
}
const setProgressThrottled = throttle({ interval: 500 }, async (progress: number) =>
await getCurrent().setProgressBar({
status: ProgressBarStatus.Normal,
progress,
}));
watch([progress, status], async () => {
switch (status.value) {
case FlashStatus.CONNECTING:
Expand All @@ -308,10 +315,7 @@ watch([progress, status], async () => {
});
break;
case FlashStatus.FLASHING:
await getCurrent().setProgressBar({
status: ProgressBarStatus.Normal,
progress: Math.round(progress.progress * 100),
});
setProgressThrottled(Math.round(progress.progress * 100));
break;
case FlashStatus.STOPPED:
case FlashStatus.SUCCESS:
Expand Down

0 comments on commit 8283e03

Please sign in to comment.