allow deleting supporting files only

without closing file
closes #1703

also fix broken migration logic
pull/1717/head
Mikael Finstad 2 years ago
parent 03a4bb914f
commit ecc852a2bc
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -123,7 +123,7 @@ const defaults = {
enableNativeHevc: true,
enableUpdateCheck: true,
cleanupChoices: {
trashTmpFiles: true, askForCleanup: true,
trashTmpFiles: true, askForCleanup: true, closeFile: true,
},
allowMultipleInstances: false,
darkMode: true,
@ -165,10 +165,7 @@ function reset(key) {
set(key, defaults[key]);
}
async function init() {
const customStoragePath = await getCustomStoragePath();
if (customStoragePath) logger.info('customStoragePath', customStoragePath);
async function tryCreateStore({ customStoragePath }) {
for (let i = 0; i < 5; i += 1) {
try {
store = new Store({ defaults, cwd: customStoragePath });
@ -180,6 +177,15 @@ async function init() {
}
}
throw new Error('Timed out while creating config store');
}
async function init() {
const customStoragePath = await getCustomStoragePath();
if (customStoragePath) logger.info('customStoragePath', customStoragePath);
await tryCreateStore({ customStoragePath });
// migrate old configs:
const enableTransferTimestamps = store.get('enableTransferTimestamps'); // todo remove after a while
if (enableTransferTimestamps != null) {
@ -188,7 +194,13 @@ async function init() {
set('treatOutputFileModifiedTimeAsStart', enableTransferTimestamps ? true : undefined);
}
throw new Error('Timed out while creating config store');
const cleanupChoices = store.get('cleanupChoices'); // todo remove after a while
if (cleanupChoices != null) {
if (cleanupChoices.closeFile == null) {
logger.info('Migrating cleanupChoices.closeFile');
set('cleanupChoices', { ...cleanupChoices, closeFile: true });
}
}
}
module.exports = {

@ -1054,10 +1054,12 @@ const App = memo(() => {
// Store paths before we reset state
const savedPaths = { previewFilePath, sourceFilePath: filePath, projectFilePath: projectFileSavePath };
batchListRemoveFile(savedPaths.sourceFilePath);
if (cleanupChoices2.closeFile) {
batchListRemoveFile(savedPaths.sourceFilePath);
// close the file
resetState();
// close the file
resetState();
}
try {
setWorking(i18n.t('Cleaning up'));
@ -1082,9 +1084,7 @@ const App = memo(() => {
return trashResponse;
}, [cleanupChoices, setCleanupChoices]);
const cleanupFilesDialog = useCallback(async () => {
if (!isFileOpened) return;
const cleanupFilesWithDialog = useCallback(async () => {
let response = cleanupChoices;
if (cleanupChoices.askForCleanup) {
response = await askForCleanupChoices();
@ -1092,14 +1092,19 @@ const App = memo(() => {
if (!response) return; // Canceled
}
await cleanupFiles(response);
}, [askForCleanupChoices, cleanupChoices, cleanupFiles]);
const cleanupFilesDialog = useCallback(async () => {
if (!isFileOpened) return;
if (workingRef.current) return;
try {
await cleanupFiles(response);
await cleanupFilesWithDialog();
} finally {
setWorking();
}
}, [isFileOpened, cleanupChoices, askForCleanupChoices, cleanupFiles, setWorking]);
}, [cleanupFilesWithDialog, isFileOpened, setWorking]);
const generateOutSegFileNames = useCallback(({ segments = segmentsToExport, template, forceSafeOutputFileName }) => (
generateOutSegFileNamesRaw({ segments, template, forceSafeOutputFileName, formatTimecode, isCustomFormatSelected, fileFormat, filePath, safeOutputFileName, maxLabelLength, outputFileNameMinZeroPadding })
@ -1231,7 +1236,7 @@ const App = memo(() => {
const revealPath = willMerge ? mergedOutFilePath : outFiles[0];
if (!hideAllNotifications) openExportFinishedToast({ filePath: revealPath, warnings, notices });
if (cleanupChoices.cleanupAfterExport) await cleanupFiles(cleanupChoices);
if (cleanupChoices.cleanupAfterExport) await cleanupFilesWithDialog();
} catch (err) {
if (err.killed === true) {
// assume execa killed (aborted by user)
@ -1255,7 +1260,7 @@ const App = memo(() => {
setWorking();
setCutProgress();
}
}, [numStreamsToCopy, setWorking, segmentsToChaptersOnly, outSegTemplateOrDefault, generateOutSegFileNames, segmentsToExport, getOutSegError, 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, cleanupFiles, selectedSegmentsOrInverse, segmentsToChapters, invertCutSegments, autoConcatCutSegments, autoDeleteMergedSegments, nonCopiedExtraStreams, filePath, handleExportFailed]);
}, [numStreamsToCopy, setWorking, segmentsToChaptersOnly, outSegTemplateOrDefault, generateOutSegFileNames, segmentsToExport, getOutSegError, 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, cleanupFilesWithDialog, selectedSegmentsOrInverse, segmentsToChapters, invertCutSegments, autoConcatCutSegments, autoDeleteMergedSegments, nonCopiedExtraStreams, filePath, handleExportFailed]);
const onExportPress = useCallback(async () => {
if (!filePath || workingRef.current || segmentsToExport.length < 1) return;

@ -336,28 +336,39 @@ const CleanupChoices = ({ cleanupChoicesInitial, onChange: onChangeProp }) => {
const getVal = (key) => !!choices[key];
const onChange = (key, val) => setChoices((c) => {
const newChoices = { ...c, [key]: val };
const onChange = (key, val) => setChoices((oldChoices) => {
const newChoices = { ...oldChoices, [key]: val };
if ((newChoices.trashSourceFile || newChoices.trashTmpFiles) && !newChoices.closeFile) {
newChoices.closeFile = true;
}
onChangeProp(newChoices);
return newChoices;
});
const trashTmpFiles = getVal('trashTmpFiles');
const trashSourceFile = getVal('trashSourceFile');
const trashProjectFile = getVal('trashProjectFile');
const deleteIfTrashFails = getVal('deleteIfTrashFails');
const closeFile = getVal('closeFile');
const askForCleanup = getVal('askForCleanup');
const cleanupAfterExport = getVal('cleanupAfterExport');
return (
<div style={{ textAlign: 'left' }}>
<p>{i18n.t('What do you want to do after exporting a file or when pressing the "delete source file" button?')}</p>
<Checkbox label={i18n.t('Close currently opened file')} checked disabled />
<Checkbox label={i18n.t('Close currently opened file')} checked={closeFile} disabled={trashSourceFile || trashTmpFiles} onChange={(e) => onChange('closeFile', e.target.checked)} />
<div style={{ marginTop: 25 }}>
<Checkbox label={i18n.t('Trash auto-generated files')} checked={getVal('trashTmpFiles')} onChange={(e) => onChange('trashTmpFiles', e.target.checked)} />
<Checkbox label={i18n.t('Trash project LLC file')} checked={getVal('trashProjectFile')} onChange={(e) => onChange('trashProjectFile', e.target.checked)} />
<Checkbox label={i18n.t('Trash original source file')} checked={getVal('trashSourceFile')} onChange={(e) => onChange('trashSourceFile', e.target.checked)} />
<Checkbox label={i18n.t('Permanently delete the files if trash fails?')} disabled={!(getVal('trashTmpFiles') || getVal('trashProjectFile') || getVal('trashSourceFile'))} checked={getVal('deleteIfTrashFails')} onChange={(e) => onChange('deleteIfTrashFails', e.target.checked)} />
<Checkbox label={i18n.t('Trash auto-generated files')} checked={trashTmpFiles} onChange={(e) => onChange('trashTmpFiles', e.target.checked)} />
<Checkbox label={i18n.t('Trash original source file')} checked={trashSourceFile} onChange={(e) => onChange('trashSourceFile', e.target.checked)} />
<Checkbox label={i18n.t('Trash project LLC file')} checked={trashProjectFile} onChange={(e) => onChange('trashProjectFile', e.target.checked)} />
<Checkbox label={i18n.t('Permanently delete the files if trash fails?')} disabled={!(trashTmpFiles || trashProjectFile || trashSourceFile)} checked={deleteIfTrashFails} onChange={(e) => onChange('deleteIfTrashFails', e.target.checked)} />
</div>
<div style={{ marginTop: 25 }}>
<Checkbox label={i18n.t('Show this dialog every time?')} checked={getVal('askForCleanup')} onChange={(e) => onChange('askForCleanup', e.target.checked)} />
<Checkbox label={i18n.t('Do all of this automatically after exporting a file?')} checked={getVal('cleanupAfterExport')} onChange={(e) => onChange('cleanupAfterExport', e.target.checked)} />
<Checkbox label={i18n.t('Show this dialog every time?')} checked={askForCleanup} onChange={(e) => onChange('askForCleanup', e.target.checked)} />
<Checkbox label={i18n.t('Do all of this automatically after exporting a file?')} checked={cleanupAfterExport} onChange={(e) => onChange('cleanupAfterExport', e.target.checked)} />
</div>
</div>
);

Loading…
Cancel
Save