From 78a8064e35ca7f8e80062e86cafb2579c022b61e Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Fri, 28 Feb 2020 17:43:47 +0800 Subject: [PATCH] Only ask confirm if file opened #261 --- src/renderer.jsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/renderer.jsx b/src/renderer.jsx index c86c0bbb..4fd8c161 100644 --- a/src/renderer.jsx +++ b/src/renderer.jsx @@ -261,6 +261,8 @@ const App = memo(() => { setThumbnails([]); }, [cutSegmentsHistory, cancelCutSegmentsDebounce, setCutSegments, cancelWaveformDataDebounce, cancelReadKeyframeDataDebounce]); + const isFileOpened = !!filePath; + function setTimelineMode(newMode) { if (newMode === 'waveform') { setWaveformEnabled(v => !v); @@ -1094,8 +1096,8 @@ const App = memo(() => { }, []); useEffect(() => { - electron.ipcRenderer.send('setAskBeforeClose', askBeforeClose); - }, [askBeforeClose]); + electron.ipcRenderer.send('setAskBeforeClose', askBeforeClose && isFileOpened); + }, [askBeforeClose, isFileOpened]); const extractAllStreams = useCallback(async () => { if (!filePath) return; @@ -1134,7 +1136,7 @@ const App = memo(() => { const firstFile = filePaths[0]; - if (!filePath) { + if (!isFileOpened) { load(firstFile); return; } @@ -1157,7 +1159,7 @@ const App = memo(() => { addStreamSourceFile(firstFile); setStreamsSelectorShown(true); } - }, [addStreamSourceFile, filePath, load, mergeFiles]); + }, [addStreamSourceFile, isFileOpened, load, mergeFiles]); const onDrop = useCallback(async (ev) => { ev.preventDefault(); @@ -1177,6 +1179,7 @@ const App = memo(() => { } function closeFile() { + if (!isFileOpened) return; // eslint-disable-next-line no-alert if (askBeforeClose && !window.confirm('Are you sure you want to close the current file? You will lose all unsaved work')) return; @@ -1247,7 +1250,7 @@ const App = memo(() => { } async function importEdlFile() { - if (!filePath) return; + if (!isFileOpened) return; const { canceled, filePaths } = await dialog.showOpenDialog({ properties: ['openFile'], filters: [{ name: 'CSV files', extensions: ['csv'] }] }); if (canceled || filePaths.length < 1) return; await loadEdlFile(filePaths[0]); @@ -1283,7 +1286,7 @@ const App = memo(() => { electron.ipcRenderer.removeListener('openHelp', openHelp); }; }, [ - load, mergeFiles, outputDir, filePath, customOutDir, startTimeOffset, getHtml5ifiedPath, + load, mergeFiles, outputDir, filePath, isFileOpened, customOutDir, startTimeOffset, getHtml5ifiedPath, createDummyVideo, resetState, extractAllStreams, userOpenFiles, cutSegmentsHistory, loadEdlFile, cutSegments, edlFilePath, askBeforeClose, toggleHelp, ]); @@ -1456,7 +1459,7 @@ const App = memo(() => { /> - {!filePath && ( + {!isFileOpened && (
DROP VIDEO(S)
@@ -1537,7 +1540,7 @@ const App = memo(() => {
)} - {filePath && ( + {isFileOpened && (