From 55131fde627de19324b7ce063dedf154c130942f Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Thu, 20 Feb 2020 12:03:25 +0800 Subject: [PATCH] config quit confirm #252 --- src/index.js | 8 ++ src/renderer.jsx | 237 +++++++++++++++++++++++++---------------------- 2 files changed, 134 insertions(+), 111 deletions(-) diff --git a/src/index.js b/src/index.js index fa9396ea..f333a05b 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,8 @@ if (!isDev) process.env.NODE_ENV = 'production'; // be closed automatically when the JavaScript object is garbage collected. let mainWindow; +let askBeforeClose = false; + function createWindow() { mainWindow = new BrowserWindow({ darkTheme: true, @@ -34,6 +36,8 @@ function createWindow() { // https://stackoverflow.com/questions/39574636/prompt-to-save-quit-before-closing-window/47434365 mainWindow.on('close', (e) => { + if (!askBeforeClose) return; + const choice = electron.dialog.showMessageBoxSync(mainWindow, { type: 'question', buttons: ['Yes', 'No'], @@ -79,3 +83,7 @@ electron.ipcMain.on('renderer-ready', () => { if (fileToOpen && !fileToOpen.startsWith('-psn_')) mainWindow.webContents.send('file-opened', [fileToOpen]); } }); + +electron.ipcMain.on('setAskBeforeClose', (e, val) => { + askBeforeClose = val; +}); diff --git a/src/renderer.jsx b/src/renderer.jsx index 4b3694a1..31901843 100644 --- a/src/renderer.jsx +++ b/src/renderer.jsx @@ -117,6 +117,7 @@ const App = memo(() => { const [mifiLink, setMifiLink] = useState(); const [invertCutSegments, setInvertCutSegments] = useState(false); const [autoExportExtraStreams, setAutoExportExtraStreams] = useState(true); + const [askBeforeClose, setAskBeforeClose] = useState(true); const videoRef = useRef(); const timelineWrapperRef = useRef(); @@ -808,6 +809,10 @@ const App = memo(() => { electron.ipcRenderer.send('renderer-ready'); }, []); + useEffect(() => { + electron.ipcRenderer.send('setAskBeforeClose', askBeforeClose); + }, [askBeforeClose]); + const extractAllStreams = useCallback(async () => { if (!filePath) return; @@ -1053,117 +1058,127 @@ const App = memo(() => { ); } - function renderSettings() { - return ( - - - Output format (default autodetected) - {renderOutFmt()} - - - - Output directory - - -
{customOutDir}
- - - - - Auto merge segments to one file after export? - - - - - - - keyframe cut mode - - - - - - - - Discard (cut away) or keep selected segments from video when exporting - - - - - - - - - Discard audio? - - - - - - - - - Extract unprocessable tracks to separate files?
- (data tracks such as GoPro GPS, telemetry etc. are not copied over by default because ffmpeg cannot cut them, thus they will cause the media duration to stay the same after cutting video/audio) - - - - - - - - - Snapshot capture format - - - {renderCaptureFormatButton()} - - - - - In timecode show - - - - -
- ); - } + const renderSettings = () => ( + + + Output format (default autodetected) + {renderOutFmt()} + + + + Output directory + + +
{customOutDir}
+ + + + + Auto merge segments to one file after export? + + + + + + + keyframe cut mode + + + + + + + + Discard (cut away) or keep selected segments from video when exporting + + + + + + + + + Discard audio? + + + + + + + + + Extract unprocessable tracks to separate files?
+ (data tracks such as GoPro GPS, telemetry etc. are not copied over by default because ffmpeg cannot cut them, thus they will cause the media duration to stay the same after cutting video/audio) + + + + + + + + + Snapshot capture format + + + {renderCaptureFormatButton()} + + + + + In timecode show + + + + + + + Ask for confirmation when closing app? + + + + +
+ ); useEffect(() => { loadMifiLink().then(setMifiLink);