From f6c126658876a8168c8cadf5398f4601aae7dc3c Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Thu, 26 Sep 2024 09:18:08 +0300 Subject: [PATCH] fix progress bug closes #2161 --- src/renderer/src/App.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index cdc877e1..e7b7b656 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -1178,19 +1178,20 @@ function App() { setCutProgress(0); let lastOutPath: string | undefined; - let totalProgress = 0; - const onProgress = (progress: number) => { - totalProgress += progress; + const segmentProgresses: Record = {}; + const handleSegmentProgress = (segIndex: number, progress: number) => { + segmentProgresses[segIndex] = progress; + const totalProgress = segments.reduce((acc, _ignored, index) => acc + (segmentProgresses[index] ?? 0), 0); setCutProgress(totalProgress / segments.length); }; // eslint-disable-next-line no-restricted-syntax - for (const segment of segments) { + for (const [index, segment] of segments.entries()) { const { start, end } = segment; if (filePath == null) throw new Error(); // eslint-disable-next-line no-await-in-loop - lastOutPath = await captureFramesRange({ customOutDir, filePath, fps: detectedFps, fromTime: start, toTime: end, estimatedMaxNumFiles: captureFramesResponse.estimatedMaxNumFiles, captureFormat, quality: captureFrameQuality, filter: captureFramesResponse.filter, outputTimestamps: captureFrameFileNameFormat === 'timestamp', onProgress }); + lastOutPath = await captureFramesRange({ customOutDir, filePath, fps: detectedFps, fromTime: start, toTime: end, estimatedMaxNumFiles: captureFramesResponse.estimatedMaxNumFiles, captureFormat, quality: captureFrameQuality, filter: captureFramesResponse.filter, outputTimestamps: captureFrameFileNameFormat === 'timestamp', onProgress: (progress) => handleSegmentProgress(index, progress) }); } if (!hideAllNotifications && lastOutPath != null) { showOsNotification(i18n.t('Frames have been extracted'));