From 1f9c3362275e71743e87b7dbc7938492ec7b34db Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sat, 30 Dec 2023 18:08:04 +0800 Subject: [PATCH] reset merged out file name on export closes #1757 --- src/App.jsx | 24 ++++++++++++++---------- src/components/MergedOutFileName.jsx | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 43456619..5218e62a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -138,7 +138,7 @@ const App = memo(() => { const [hideCanvasPreview, setHideCanvasPreview] = useState(false); const [exportConfirmVisible, setExportConfirmVisible] = useState(false); const [cacheBuster, setCacheBuster] = useState(0); - const [customMergedOutFileName, setMergedOutFileName] = useState(); + const [mergedOutFileName, setMergedOutFileName] = useState(); const [outputPlaybackRate, setOutputPlaybackRateState] = useState(1); const { fileFormat, setFileFormat, detectedFileFormat, setDetectedFileFormat, isCustomFormatSelected } = useFileFormatState(); @@ -703,6 +703,14 @@ const App = memo(() => { const { neighbouringKeyFrames, findNearestKeyFrameTime } = useKeyframes({ keyframesEnabled, filePath, commandedTime, mainVideoStream, detectedFps, ffmpegExtractWindow }); const { waveforms } = useWaveform({ darkMode, filePath, relevantTime, waveformEnabled, mainAudioStream, shouldShowWaveform, ffmpegExtractWindow, durationSafe }); + const resetMergedOutFileName = useCallback(() => { + const ext = getOutFileExtension({ isCustomFormatSelected, outFormat: fileFormat, filePath }); + const outFileName = getSuffixedFileName(filePath, `cut-merged-${new Date().getTime()}${ext}`); + setMergedOutFileName(outFileName); + }, [fileFormat, filePath, isCustomFormatSelected]); + + useEffect(() => resetMergedOutFileName(), [resetMergedOutFileName]); + const resetState = useCallback(() => { console.log('State reset'); const video = videoRef.current; @@ -743,11 +751,11 @@ const App = memo(() => { setActiveSubtitleStreamIndex(); setHideCanvasPreview(false); setExportConfirmVisible(false); - setMergedOutFileName(); + resetMergedOutFileName(); setOutputPlaybackRateState(1); cancelRenderThumbnails(); - }, [cutSegmentsHistory, clearSegments, setFileFormat, setDetectedFileFormat, setDeselectedSegmentIds, cancelRenderThumbnails]); + }, [cutSegmentsHistory, clearSegments, setFileFormat, setDetectedFileFormat, setDeselectedSegmentIds, resetMergedOutFileName, cancelRenderThumbnails]); const showUnsupportedFileMessage = useCallback(() => { @@ -1128,12 +1136,6 @@ const App = memo(() => { const willMerge = segmentsToExport.length > 1 && autoMerge; - const mergedOutFileName = useMemo(() => { - if (customMergedOutFileName != null) return customMergedOutFileName; - const ext = getOutFileExtension({ isCustomFormatSelected, outFormat: fileFormat, filePath }); - return getSuffixedFileName(filePath, `cut-merged-${new Date().getTime()}${ext}`); - }, [customMergedOutFileName, fileFormat, filePath, isCustomFormatSelected]); - const mergedOutFilePath = useMemo(() => ( getOutPath({ customOutDir, filePath, fileName: mergedOutFileName }) ), [customOutDir, filePath, mergedOutFileName]); @@ -1257,6 +1259,8 @@ const App = memo(() => { if (!hideAllNotifications) openExportFinishedToast({ filePath: revealPath, warnings, notices }); if (cleanupChoices.cleanupAfterExport) await cleanupFilesWithDialog(); + + resetMergedOutFileName(); } catch (err) { if (err.killed === true) { // assume execa killed (aborted by user) @@ -1280,7 +1284,7 @@ const App = memo(() => { setWorking(); setCutProgress(); } - }, [numStreamsToCopy, segmentsToExport, haveInvalidSegs, setWorking, segmentsToChaptersOnly, outSegTemplateOrDefault, generateOutSegFileNames, cutMultiple, outputDir, customOutDir, fileFormat, duration, isRotationSet, effectiveRotation, copyFileStreams, allFilesMeta, keyframeCut, shortestFlag, ffmpegExperimental, preserveMovData, preserveMetadataOnMerge, movFastStart, avoidNegativeTs, customTagsByFile, paramsByStreamId, detectedFps, willMerge, enableOverwriteOutput, exportConfirmEnabled, mainFileFormatData, mainStreams, exportExtraStreams, areWeCutting, mergedOutFilePath, hideAllNotifications, cleanupChoices.cleanupAfterExport, cleanupFilesWithDialog, selectedSegmentsOrInverse, segmentsToChapters, invertCutSegments, autoConcatCutSegments, autoDeleteMergedSegments, nonCopiedExtraStreams, filePath, handleExportFailed]); + }, [numStreamsToCopy, segmentsToExport, haveInvalidSegs, setWorking, segmentsToChaptersOnly, outSegTemplateOrDefault, generateOutSegFileNames, cutMultiple, outputDir, customOutDir, fileFormat, duration, isRotationSet, effectiveRotation, copyFileStreams, allFilesMeta, keyframeCut, shortestFlag, ffmpegExperimental, preserveMovData, preserveMetadataOnMerge, movFastStart, avoidNegativeTs, customTagsByFile, paramsByStreamId, detectedFps, willMerge, enableOverwriteOutput, exportConfirmEnabled, mainFileFormatData, mainStreams, exportExtraStreams, areWeCutting, mergedOutFilePath, hideAllNotifications, cleanupChoices.cleanupAfterExport, cleanupFilesWithDialog, resetMergedOutFileName, selectedSegmentsOrInverse, segmentsToChapters, invertCutSegments, autoConcatCutSegments, autoDeleteMergedSegments, nonCopiedExtraStreams, filePath, handleExportFailed]); const onExportPress = useCallback(async () => { if (!filePath) return; diff --git a/src/components/MergedOutFileName.jsx b/src/components/MergedOutFileName.jsx index d2d4ef3b..9c69149c 100644 --- a/src/components/MergedOutFileName.jsx +++ b/src/components/MergedOutFileName.jsx @@ -5,7 +5,7 @@ import TextInput from './TextInput'; const MergedOutFileName = memo(({ mergedOutFileName, setMergedOutFileName }) => (
- setMergedOutFileName(e.target.value)} style={{ textAlign: 'right' }} /> + setMergedOutFileName(e.target.value)} style={{ textAlign: 'right' }} />
));