From 274e67ff457e22ecacea993fe9469d167b4d9f5d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 4 Apr 2024 12:05:33 +0200 Subject: [PATCH] don't close the app when an error has been raised --- src/main.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 06d6d54..ad21faf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,8 @@ import { import path = require("path"); import ffmpegPath = require("ffmpeg-static"); +let error = false; + const moviesFilter = { name: "Videos", extensions: ["mp4", "mkv"], @@ -22,6 +24,12 @@ const metadataAudio = `-metadata:s:a:0 title="System sounds and microphone" \ const extraArgs = "-movflags +faststart"; +/** Register a new error */ +const registerError = (win: BrowserWindow, err: string) => { + error = true; + printAndDevTool(win, err); +}; + /** Create a new window */ const createWindow = () => { const win = new BrowserWindow({ @@ -92,13 +100,13 @@ app.whenReady().then(() => { -i "${file}" \ -codec copy \ ${extraArgs} \ - "${outFile}"`).catch((e) => printAndDevTool(win, e)); + "${outFile}"`).catch((e) => registerError(win, e)); // We throw the error since we do not want to merge any audio return Promise.resolve("skip"); } else { // Error handling - printAndDevTool(win, e); + registerError(win, e); } }) .then(async (val) => { @@ -119,7 +127,7 @@ app.whenReady().then(() => { ${metadataAudio} \ ${extraArgs} \ "${outFile}"` - ).catch((e) => printAndDevTool(win, e)); + ).catch((e) => registerError(win, e)); // Delete the temporary video file deleteFile(tmpFile); @@ -186,7 +194,7 @@ app.whenReady().then(() => { ${metadataAudio} \ ${extraArgs} \ "${finalFile}"` - ).catch((e) => printAndDevTool(win, e)); + ).catch((e) => registerError(win, e)); // Delete the old video file deleteFile(file); @@ -208,6 +216,6 @@ app.whenReady().then(() => { (_, file: string, bitrate: number, nbTracks: number) => reduceSize(file, bitrate, nbTracks) ); - ipcMain.handle("exit", () => app.quit()); + ipcMain.handle("exit", () => (error ? {} : app.quit())); ipcMain.handle("confirmation", (_, text: string) => confirmation(text)); });