don't close the app when an error has been raised
This commit is contained in:
parent
3e57b75145
commit
274e67ff45
1 changed files with 13 additions and 5 deletions
18
src/main.ts
18
src/main.ts
|
@ -11,6 +11,8 @@ import {
|
||||||
import path = require("path");
|
import path = require("path");
|
||||||
import ffmpegPath = require("ffmpeg-static");
|
import ffmpegPath = require("ffmpeg-static");
|
||||||
|
|
||||||
|
let error = false;
|
||||||
|
|
||||||
const moviesFilter = {
|
const moviesFilter = {
|
||||||
name: "Videos",
|
name: "Videos",
|
||||||
extensions: ["mp4", "mkv"],
|
extensions: ["mp4", "mkv"],
|
||||||
|
@ -22,6 +24,12 @@ const metadataAudio = `-metadata:s:a:0 title="System sounds and microphone" \
|
||||||
|
|
||||||
const extraArgs = "-movflags +faststart";
|
const extraArgs = "-movflags +faststart";
|
||||||
|
|
||||||
|
/** Register a new error */
|
||||||
|
const registerError = (win: BrowserWindow, err: string) => {
|
||||||
|
error = true;
|
||||||
|
printAndDevTool(win, err);
|
||||||
|
};
|
||||||
|
|
||||||
/** Create a new window */
|
/** Create a new window */
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
const win = new BrowserWindow({
|
const win = new BrowserWindow({
|
||||||
|
@ -92,13 +100,13 @@ app.whenReady().then(() => {
|
||||||
-i "${file}" \
|
-i "${file}" \
|
||||||
-codec copy \
|
-codec copy \
|
||||||
${extraArgs} \
|
${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
|
// We throw the error since we do not want to merge any audio
|
||||||
return Promise.resolve("skip");
|
return Promise.resolve("skip");
|
||||||
} else {
|
} else {
|
||||||
// Error handling
|
// Error handling
|
||||||
printAndDevTool(win, e);
|
registerError(win, e);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(async (val) => {
|
.then(async (val) => {
|
||||||
|
@ -119,7 +127,7 @@ app.whenReady().then(() => {
|
||||||
${metadataAudio} \
|
${metadataAudio} \
|
||||||
${extraArgs} \
|
${extraArgs} \
|
||||||
"${outFile}"`
|
"${outFile}"`
|
||||||
).catch((e) => printAndDevTool(win, e));
|
).catch((e) => registerError(win, e));
|
||||||
|
|
||||||
// Delete the temporary video file
|
// Delete the temporary video file
|
||||||
deleteFile(tmpFile);
|
deleteFile(tmpFile);
|
||||||
|
@ -186,7 +194,7 @@ app.whenReady().then(() => {
|
||||||
${metadataAudio} \
|
${metadataAudio} \
|
||||||
${extraArgs} \
|
${extraArgs} \
|
||||||
"${finalFile}"`
|
"${finalFile}"`
|
||||||
).catch((e) => printAndDevTool(win, e));
|
).catch((e) => registerError(win, e));
|
||||||
|
|
||||||
// Delete the old video file
|
// Delete the old video file
|
||||||
deleteFile(file);
|
deleteFile(file);
|
||||||
|
@ -208,6 +216,6 @@ app.whenReady().then(() => {
|
||||||
(_, file: string, bitrate: number, nbTracks: number) =>
|
(_, file: string, bitrate: number, nbTracks: number) =>
|
||||||
reduceSize(file, bitrate, nbTracks)
|
reduceSize(file, bitrate, nbTracks)
|
||||||
);
|
);
|
||||||
ipcMain.handle("exit", () => app.quit());
|
ipcMain.handle("exit", () => (error ? {} : app.quit()));
|
||||||
ipcMain.handle("confirmation", (_, text: string) => confirmation(text));
|
ipcMain.handle("confirmation", (_, text: string) => confirmation(text));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue