From 617731b86ccbca13f50fc424cfa8f54a248e8f1b Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Thu, 15 Aug 2024 14:57:14 +0200 Subject: [PATCH] improve startup check also run it even if we have a customFfPath closes #2070 --- src/renderer/src/App.tsx | 5 ++--- src/renderer/src/mifi.ts | 32 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 5d125882..ccc919d3 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -2623,10 +2623,9 @@ function App() { if (!isStoreBuild && !hasDisabledNetworking()) loadMifiLink().then(setMifiLink); }, []); - const haveCustomFfPath = !!customFfPath; useEffect(() => { - runStartupCheck({ ffmpeg: !haveCustomFfPath }); - }, [haveCustomFfPath]); + runStartupCheck({ customFfPath }); + }, [customFfPath]); useEffect(() => { const keyScrollPreventer = (e) => { diff --git a/src/renderer/src/mifi.ts b/src/renderer/src/mifi.ts index fa3af799..ac39d056 100644 --- a/src/renderer/src/mifi.ts +++ b/src/renderer/src/mifi.ts @@ -1,7 +1,7 @@ import ky from 'ky'; import { runFfmpegStartupCheck, getFfmpegPath } from './ffmpeg'; -import { toast } from './swal'; +import Swal from './swal'; import { handleError } from './util'; import isDev from './isDev'; @@ -17,18 +17,28 @@ export async function loadMifiLink() { } } -export async function runStartupCheck({ ffmpeg }: { ffmpeg: boolean }) { +export async function runStartupCheck({ customFfPath }: { customFfPath: string | undefined }) { try { - if (ffmpeg) await runFfmpegStartupCheck(); + await runFfmpegStartupCheck(); } catch (err) { - if (err instanceof Error && 'code' in err && typeof err.code === 'string' && ['EPERM', 'EACCES'].includes(err.code)) { - toast.fire({ - timer: 30000, - icon: 'error', - title: 'Fatal: ffmpeg not accessible', - text: `Got ${err.code}. This probably means that anti-virus is blocking execution of ffmpeg. Please make sure the following file exists and is executable:\n\n${getFfmpegPath()}\n\nSee this issue: https://github.com/mifi/lossless-cut/issues/1114`, - }); - return; + if (err instanceof Error) { + if (!customFfPath && 'code' in err && typeof err.code === 'string' && ['EPERM', 'EACCES'].includes(err.code)) { + Swal.fire({ + icon: 'error', + title: 'Fatal: ffmpeg not accessible', + text: `Got ${err.code}. This probably means that anti-virus is blocking execution of ffmpeg. Please make sure the following file exists and is executable:\n\n${getFfmpegPath()}\n\nSee this issue: https://github.com/mifi/lossless-cut/issues/1114`, + }); + return; + } + + if (customFfPath && 'code' in err && err.code === 'ENOENT') { + Swal.fire({ + icon: 'error', + title: 'Fatal: ffmpeg not found', + text: `Make sure that ffmpeg executable exists: ${getFfmpegPath()}`, + }); + return; + } } handleError('Fatal: ffmpeg non-functional', err);