add logging when saving #2496

pull/2531/head
Mikael Finstad 11 months ago
parent 25082978d6
commit 250829ba45
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -81,14 +81,14 @@ export async function saveSrt(path: string, cutSegments: SegmentBase[]) {
await writeFile(path, formatSrt(cutSegments)); await writeFile(path, formatSrt(cutSegments));
} }
export async function saveLlcProject({ savePath, filePath, cutSegments }: { export async function saveLlcProject({ savePath, mediaFilePath, cutSegments }: {
savePath: string, savePath: string,
filePath: string, mediaFilePath: string,
cutSegments: StateSegment[], cutSegments: StateSegment[],
}) { }) {
const projectData: LlcProject = { const projectData: LlcProject = {
version: 2, version: 2,
mediaFileName: basename(filePath), mediaFileName: basename(mediaFilePath),
cutSegments: mapSaveableSegments(cutSegments), cutSegments: mapSaveableSegments(cutSegments),
}; };
await writeFile(savePath, JSON5.stringify(projectData, null, 2)); await writeFile(savePath, JSON5.stringify(projectData, null, 2));
@ -222,6 +222,6 @@ export async function exportEdlFile({ type, cutSegments, customOutDir, filePath,
else if (type === 'tsv-human') await saveTsv(savePath, cutSegments); else if (type === 'tsv-human') await saveTsv(savePath, cutSegments);
else if (type === 'csv-human') await saveCsvHuman(savePath, cutSegments); else if (type === 'csv-human') await saveCsvHuman(savePath, cutSegments);
else if (type === 'csv-frames') await saveCsvFrames({ path: savePath, cutSegments, getFrameCount }); else if (type === 'csv-frames') await saveCsvFrames({ path: savePath, cutSegments, getFrameCount });
else if (type === 'llc') await saveLlcProject({ savePath, filePath, cutSegments }); else if (type === 'llc') await saveLlcProject({ savePath, mediaFilePath: filePath, cutSegments });
else if (type === 'srt') await saveSrt(savePath, cutSegments); else if (type === 'srt') await saveSrt(savePath, cutSegments);
} }

@ -29,6 +29,7 @@ export default ({ autoSaveProjectFile, storeProjectInWorkingDir, filePath, custo
return { cutSegments, projectFileSavePath, filePath }; return { cutSegments, projectFileSavePath, filePath };
}, [cutSegments, filePath, projectFileSavePath]); }, [cutSegments, filePath, projectFileSavePath]);
// NOTE: Could lose a save if user closes too fast, but not a big issue I think
const [debouncedSaveOperation] = useDebounce(currentSaveOperation, isDev ? 2000 : 500); const [debouncedSaveOperation] = useDebounce(currentSaveOperation, isDev ? 2000 : 500);
const lastSaveOperation = useRef<typeof debouncedSaveOperation>(); const lastSaveOperation = useRef<typeof debouncedSaveOperation>();
@ -36,7 +37,6 @@ export default ({ autoSaveProjectFile, storeProjectInWorkingDir, filePath, custo
useEffect(() => { useEffect(() => {
async function save() { async function save() {
try { try {
// NOTE: Could lose a save if user closes too fast, but not a big issue I think
if (!autoSaveProjectFile if (!autoSaveProjectFile
|| !debouncedSaveOperation || !debouncedSaveOperation
|| debouncedSaveOperation.filePath == null || debouncedSaveOperation.filePath == null
@ -49,7 +49,8 @@ export default ({ autoSaveProjectFile, storeProjectInWorkingDir, filePath, custo
return; return;
} }
await saveLlcProject({ savePath: debouncedSaveOperation.projectFileSavePath, filePath: debouncedSaveOperation.filePath, cutSegments: debouncedSaveOperation.cutSegments }); console.log('Saving project file', debouncedSaveOperation.projectFileSavePath, debouncedSaveOperation.cutSegments);
await saveLlcProject({ savePath: debouncedSaveOperation.projectFileSavePath, mediaFilePath: debouncedSaveOperation.filePath, cutSegments: debouncedSaveOperation.cutSegments });
lastSaveOperation.current = debouncedSaveOperation; lastSaveOperation.current = debouncedSaveOperation;
} catch (err) { } catch (err) {
errorToast(i18n.t('Unable to save project file')); errorToast(i18n.t('Unable to save project file'));

Loading…
Cancel
Save