The swiss army knife of lossless video/audio editing
enable exactOptionalPropertyTypes
Mikael Finstadcb5a8c2c8500
diff --git a/src/App.tsx b/src/App.tsxindex 574c96a4..7ac455ef 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -111,7 +111,7 @@ function App() {const [ffmpegCommandLog, setFfmpegCommandLog] = useState<FfmpegCommandLog>([]);const [previewFilePath, setPreviewFilePath] = useState<string>();- const [working, setWorkingState] = useState<{ text: string, abortController?: AbortController }>();+ const [working, setWorkingState] = useState<{ text: string, abortController?: AbortController | undefined }>();const [usingDummyVideo, setUsingDummyVideo] = useState(false);const [playing, setPlaying] = useState(false);const [compatPlayerEventId, setCompatPlayerEventId] = useState(0);@@ -879,6 +879,7 @@ function App() {setTotalProgress();}+ // @ts-expect-error todo// eslint-disable-next-line @typescript-eslint/no-explicit-anyif (failedFiles.length > 0) toast.fire({ title: `${i18n.t('Failed to convert files:')} ${failedFiles.join(' ')}`, timer: null as any as undefined, showConfirmButton: true });} catch (err) {diff --git a/src/MediaSourcePlayer.tsx b/src/MediaSourcePlayer.tsxindex 2a781e1a..3d37952f 100644--- a/src/MediaSourcePlayer.tsx+++ b/src/MediaSourcePlayer.tsx@@ -11,15 +11,15 @@ const { createMediaSourceStream, readOneJpegFrame } = remote.require('./compatPlasync function startPlayback({ path, video, videoStreamIndex, audioStreamIndex, seekTo, signal, playSafe, onCanPlay, getTargetTime, size, fps }: {path: string,video: HTMLVideoElement,- videoStreamIndex?: number,- audioStreamIndex?: number,+ videoStreamIndex?: number | undefined,+ audioStreamIndex?: number | undefined,seekTo: number,signal: AbortSignal,playSafe: () => void,onCanPlay: () => void,getTargetTime: () => number,- size?: number,- fps?: number,+ size?: number | undefined,+ fps?: number | undefined,}) {let canPlay = false;let bufferEndTime: number | undefined;diff --git a/src/components/CaptureFormatButton.tsx b/src/components/CaptureFormatButton.tsxindex c153e291..a323f629 100644--- a/src/components/CaptureFormatButton.tsx+++ b/src/components/CaptureFormatButton.tsx@@ -11,7 +11,7 @@ const CaptureFormatButton = memo(({ showIcon = false, ...props }: { showIcon?: bconst { captureFormat, toggleCaptureFormat } = useUserSettings();return (<Button- iconBefore={showIcon ? <FaImage /> : undefined}+ iconBefore={showIcon ? <FaImage /> : null}title={t('Capture frame format')}onClick={withBlur(toggleCaptureFormat)}// eslint-disable-next-line react/jsx-props-no-spreadingdiff --git a/src/components/CopyClipboardButton.tsx b/src/components/CopyClipboardButton.tsxindex 55f347b8..fe3c0d87 100644--- a/src/components/CopyClipboardButton.tsx+++ b/src/components/CopyClipboardButton.tsx@@ -1,12 +1,12 @@-import { CSSProperties, memo, useCallback } from 'react';+import { memo, useCallback } from 'react';import { FaClipboard } from 'react-icons/fa';import { useTranslation } from 'react-i18next';-import { motion, useAnimation } from 'framer-motion';+import { MotionStyle, motion, useAnimation } from 'framer-motion';const electron = window.require('electron');const { clipboard } = electron;-const CopyClipboardButton = memo(({ text, style }: { text: string, style?: CSSProperties }) => {+const CopyClipboardButton = memo(({ text, style }: { text: string, style?: MotionStyle }) => {const { t } = useTranslation();const animation = useAnimation();diff --git a/src/components/OutSegTemplateEditor.tsx b/src/components/OutSegTemplateEditor.tsxindex e2aed2d9..4c366c17 100644--- a/src/components/OutSegTemplateEditor.tsx+++ b/src/components/OutSegTemplateEditor.tsx@@ -32,7 +32,7 @@ const OutSegTemplateEditor = memo(({ outSegTemplate, setOutSegTemplate, generateconst [text, setText] = useState(outSegTemplate);const [debouncedText] = useDebounce(text, 500);const [validText, setValidText] = useState<string>();- const [outSegProblems, setOutSegProblems] = useState<{ error?: string, sameAsInputFileNameWarning?: boolean }>({ error: undefined, sameAsInputFileNameWarning: false });+ const [outSegProblems, setOutSegProblems] = useState<{ error?: string | undefined, sameAsInputFileNameWarning?: boolean | undefined }>({ error: undefined, sameAsInputFileNameWarning: false });const [outSegFileNames, setOutSegFileNames] = useState<string[]>();const [shown, setShown] = useState<boolean>();const inputRef = useRef<HTMLInputElement>(null);diff --git a/src/components/OutputFormatSelect.tsx b/src/components/OutputFormatSelect.tsxindex 3f7d74b3..05788944 100644--- a/src/components/OutputFormatSelect.tsx+++ b/src/components/OutputFormatSelect.tsx@@ -16,7 +16,7 @@ function renderFormatOptions(formats) {}const OutputFormatSelect = memo(({ style, detectedFileFormat, fileFormat, onOutputFormatUserChange }: {- style: CSSProperties, detectedFileFormat?: string, fileFormat?: string, onOutputFormatUserChange: (a: string) => void,+ style: CSSProperties, detectedFileFormat?: string | undefined, fileFormat?: string | undefined, onOutputFormatUserChange: (a: string) => void,}) => {const commonVideoAudioFormatsExceptDetectedFormat = useMemo(() => commonVideoAudioFormats.filter((f) => f !== detectedFileFormat), [detectedFileFormat]);const commonAudioFormatsExceptDetectedFormat = useMemo(() => commonAudioFormats.filter((f) => f !== detectedFileFormat), [detectedFileFormat]);diff --git a/src/components/PlaybackStreamSelector.tsx b/src/components/PlaybackStreamSelector.tsxindex 1637c32c..3e75a721 100644--- a/src/components/PlaybackStreamSelector.tsx+++ b/src/components/PlaybackStreamSelector.tsx@@ -17,12 +17,12 @@ const PlaybackStreamSelector = memo(({subtitleStreams,videoStreams,audioStreams,- activeSubtitleStreamIndex?: number,- activeVideoStreamIndex?: number,- activeAudioStreamIndex?: number,- onActiveSubtitleChange: (a?: number) => void,- onActiveVideoStreamChange: (a?: number) => void,- onActiveAudioStreamChange: (a?: number) => void,+ activeSubtitleStreamIndex?: number | undefined,+ activeVideoStreamIndex?: number | undefined,+ activeAudioStreamIndex?: number | undefined,+ onActiveSubtitleChange: (a?: number | undefined) => void,+ onActiveVideoStreamChange: (a?: number | undefined) => void,+ onActiveAudioStreamChange: (a?: number | undefined) => void,}) => {const [controlVisible, setControlVisible] = useState(false);const timeoutRef = useRef<number>();diff --git a/src/components/SegmentCutpointButton.tsx b/src/components/SegmentCutpointButton.tsxindex 7bae1247..c449ef67 100644--- a/src/components/SegmentCutpointButton.tsx+++ b/src/components/SegmentCutpointButton.tsx@@ -5,7 +5,7 @@ import useUserSettings from '../hooks/useUserSettings';import { SegmentBase } from '../types';const SegmentCutpointButton = ({ currentCutSeg, side, Icon, onClick, title, style }: {- currentCutSeg: SegmentBase, side: 'start' | 'end', Icon, onClick?: () => void, title?: string, style?: CSSProperties+ currentCutSeg: SegmentBase, side: 'start' | 'end', Icon, onClick?: (() => void) | undefined, title?: string | undefined, style?: CSSProperties | undefined}) => {const { darkMode } = useUserSettings();const { getSegColor } = useSegColors();diff --git a/src/components/Working.tsx b/src/components/Working.tsxindex 55199c17..3c24ed7f 100644--- a/src/components/Working.tsx+++ b/src/components/Working.tsx@@ -9,7 +9,7 @@ import loadingLottie from '../7077-magic-flow.json';const Working = memo(({ text, cutProgress, onAbortClick }: {- text: string, cutProgress?: number, onAbortClick: () => void+ text: string, cutProgress?: number | undefined, onAbortClick: () => void}) => (<div style={{ position: 'absolute', bottom: 0, top: 0, left: 0, right: 0, display: 'flex', justifyContent: 'center', alignItems: 'center' }}><motion.divdiff --git a/src/dialogs/html5ify.tsx b/src/dialogs/html5ify.tsxindex 9b0c6f86..a94243f1 100644--- a/src/dialogs/html5ify.tsx+++ b/src/dialogs/html5ify.tsx@@ -12,7 +12,7 @@ const ReactSwal = withReactContent(Swal);// eslint-disable-next-line import/prefer-default-exportexport async function askForHtml5ifySpeed({ allowedOptions, showRemember, initialOption }: {- allowedOptions: Html5ifyMode[], showRemember?: boolean, initialOption?: Html5ifyMode+ allowedOptions: Html5ifyMode[], showRemember?: boolean | undefined, initialOption?: Html5ifyMode | undefined}) {const availOptions: Record<Html5ifyMode, string> = {fastest: i18n.t('Fastest: FFmpeg-assisted playback'),diff --git a/src/dialogs/index.tsx b/src/dialogs/index.tsxindex e6277168..4466e081 100644--- a/src/dialogs/index.tsx+++ b/src/dialogs/index.tsx@@ -19,7 +19,8 @@ const { dialog } = window.require('@electron/remote');const ReactSwal = withReactContent(Swal);-export async function promptTimeOffset({ initialValue, title, text }: { initialValue?: string, title: string, text?: string }) {+export async function promptTimeOffset({ initialValue, title, text }: { initialValue?: string | undefined, title: string, text?: string | undefined }) {+ // @ts-expect-error todoconst { value } = await Swal.fire({title,text,@@ -44,6 +45,7 @@ export async function promptTimeOffset({ initialValue, title, text }: { initialVexport const showOpenDialog = async ({filters = isWindows ? [{ name: i18n.t('All Files'), extensions: ['*'] }] : undefined,...props+ // @ts-expect-error todo}) => dialog.showOpenDialog({ ...props, filters });export async function askForYouTubeInput() {@@ -468,6 +470,7 @@ export async function showExportFailedDialog({ fileFormat, safeOutputFileName })</div>);+ // @ts-expect-error todo// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst { value } = await ReactSwal.fire({ title: i18n.t('Unable to export this file'), html, timer: null as any as undefined, showConfirmButton: true, showCancelButton: true, cancelButtonText: i18n.t('OK'), confirmButtonText: i18n.t('Report'), reverseButtons: true, focusCancel: true });return value;@@ -489,6 +492,7 @@ export async function showConcatFailedDialog({ fileFormat }) {</div>);+ // @ts-expect-error todo// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst { value } = await ReactSwal.fire({ title: i18n.t('Unable to merge files'), html, timer: null as any as undefined, showConfirmButton: true, showCancelButton: true, cancelButtonText: i18n.t('OK'), confirmButtonText: i18n.t('Report'), reverseButtons: true, focusCancel: true });return value;@@ -569,6 +573,7 @@ export function showJson5Dialog({ title, json }) {export async function openDirToast({ filePath, text, html, ...props }: SweetAlertOptions & { filePath: string }) {const swal = text ? toast : ReactSwal;+ // @ts-expect-error todoconst { value } = await swal.fire({...swalToastOptions,showConfirmButton: true,@@ -583,6 +588,7 @@ export async function openDirToast({ filePath, text, html, ...props }: SweetAler}const UnorderedList = ({ children }) => <ul style={{ paddingLeft: '1em' }}>{children}</ul>;+// @ts-expect-error todoconst ListItem = ({ icon: Icon, iconColor, children, style }: { icon: IconComponent, iconColor?: string, children: ReactNode, style?: CSSProperties }) => <li style={{ listStyle: 'none', ...style }}>{Icon && <Icon color={iconColor} size={14} marginRight=".3em" />} {children}</li>;const Notices = ({ notices }) => notices.map((msg) => <ListItem key={msg} icon={InfoSignIcon} iconColor="info">{msg}</ListItem>);@@ -601,6 +607,7 @@ export async function openExportFinishedToast({ filePath, warnings, notices }) {</UnorderedList>);+ // @ts-expect-error todoawait openDirToast({ filePath, html, width: 800, position: 'center', timer: hasWarnings ? undefined : 30000 });}diff --git a/src/dialogs/parameters.tsx b/src/dialogs/parameters.tsxindex c8947515..36459ba8 100644--- a/src/dialogs/parameters.tsx+++ b/src/dialogs/parameters.tsx@@ -14,7 +14,7 @@ export interface ParameterDialogParameter { value: string, label?: string, hint?export type ParameterDialogParameters = Record<string, ParameterDialogParameter>;const ParametersInput = ({ description, parameters: parametersIn, onChange, onSubmit, docUrl }: {- description?: string, parameters: ParameterDialogParameters, onChange: (a: ParameterDialogParameters) => void, onSubmit: () => void, docUrl?: string,+ description?: string | undefined, parameters: ParameterDialogParameters, onChange: (a: ParameterDialogParameters) => void, onSubmit: () => void, docUrl?: string | undefined,}) => {const firstInputRef = useRef<HTMLInputElement>(null);const [parameters, setParameters] = useState(parametersIn);@@ -67,6 +67,7 @@ export async function showParametersDialog({ title, description, parameters: par};const promise2 = (async () => {+ // @ts-expect-error todoconst { isConfirmed } = await ReactSwal.fire({title,html: <ParametersInput description={description} parameters={parameters} onChange={(newParameters) => { parameters = newParameters; }} onSubmit={handleSubmit} docUrl={docUrl} />,diff --git a/src/edlStore.ts b/src/edlStore.tsindex 264f9dc5..1194ed5c 100644--- a/src/edlStore.ts+++ b/src/edlStore.ts@@ -93,7 +93,7 @@ export async function loadLlcProject(path: string) {};}-export async function readEdlFile({ type, path, fps }: { type: EdlFileType, path: string, fps?: number }) {+export async function readEdlFile({ type, path, fps }: { type: EdlFileType, path: string, fps?: number | undefined }) {if (type === 'csv') return loadCsvSeconds(path);if (type === 'csv-frames') return loadCsvFrames(path, fps);if (type === 'xmeml') return loadXmeml(path);@@ -110,7 +110,7 @@ export async function readEdlFile({ type, path, fps }: { type: EdlFileType, paththrow new Error('Invalid EDL type');}-export async function askForEdlImport({ type, fps }: { type: EdlImportType, fps?: number }) {+export async function askForEdlImport({ type, fps }: { type: EdlImportType, fps?: number | undefined }) {if (type === 'youtube') return askForYouTubeInput();let filters;@@ -132,7 +132,7 @@ export async function askForEdlImport({ type, fps }: { type: EdlImportType, fps?}export async function exportEdlFile({ type, cutSegments, customOutDir, filePath, getFrameCount }: {- type: EdlExportType, cutSegments: Segment[], customOutDir?: string, filePath?: string, getFrameCount: (a: number) => number | undefined,+ type: EdlExportType, cutSegments: Segment[], customOutDir?: string | undefined, filePath?: string | undefined, getFrameCount: (a: number) => number | undefined,}) {let filters;let ext;diff --git a/src/hooks/useFrameCapture.ts b/src/hooks/useFrameCapture.tsindex f43e01ec..35f1ec76 100644--- a/src/hooks/useFrameCapture.ts+++ b/src/hooks/useFrameCapture.ts@@ -26,7 +26,7 @@ function getFrameFromVideo(video, format, quality) {export default ({ formatTimecode, treatOutputFileModifiedTimeAsStart }) => {const captureFramesRange = useCallback(async ({ customOutDir, filePath, fps, fromTime, toTime, estimatedMaxNumFiles, captureFormat, quality, filter, onProgress, outputTimestamps }: {- customOutDir, filePath: string, fps: number, fromTime: number, toTime: number, estimatedMaxNumFiles: number, captureFormat: string, quality: number, filter?: string, onProgress: (a: number) => void, outputTimestamps: boolean+ customOutDir, filePath: string, fps: number, fromTime: number, toTime: number, estimatedMaxNumFiles: number, captureFormat: string, quality: number, filter?: string | undefined, onProgress: (a: number) => void, outputTimestamps: boolean}) => {const getSuffix = (prefix: string) => `${prefix}.${captureFormat}`;diff --git a/src/hooks/useNativeMenu.ts b/src/hooks/useNativeMenu.tsindex 7f0c8271..e7a4039e 100644--- a/src/hooks/useNativeMenu.ts+++ b/src/hooks/useNativeMenu.ts@@ -17,6 +17,7 @@ export default function useNativeMenu(const { x, y, onContext, onClose } = options;const openMenu = useCallback((e: MouseEvent) => {+ // @ts-expect-error todomenu.popup({window: remote.getCurrentWindow(),x,diff --git a/src/hooks/useSegments.ts b/src/hooks/useSegments.tsindex 42b45ec4..9475de2a 100644--- a/src/hooks/useSegments.ts+++ b/src/hooks/useSegments.ts@@ -21,7 +21,7 @@ const { blackDetect, silenceDetect } = remote.require('./ffmpeg');export default ({ filePath, workingRef, setWorking, setCutProgress, videoStream, duration, getRelevantTime, maxLabelLength, checkFileOpened, invertCutSegments, segmentsToChaptersOnly }: {- filePath?: string, workingRef: MutableRefObject<boolean>, setWorking: (w: { text: string, abortController?: AbortController } | undefined) => void, setCutProgress: (a: number | undefined) => void, videoStream, duration?: number, getRelevantTime: () => number, maxLabelLength: number, checkFileOpened: () => boolean, invertCutSegments: boolean, segmentsToChaptersOnly: boolean,+ filePath?: string | undefined, workingRef: MutableRefObject<boolean>, setWorking: (w: { text: string, abortController?: AbortController } | undefined) => void, setCutProgress: (a: number | undefined) => void, videoStream, duration?: number | undefined, getRelevantTime: () => number, maxLabelLength: number, checkFileOpened: () => boolean, invertCutSegments: boolean, segmentsToChaptersOnly: boolean,}) => {// Segment related stateconst segCounterRef = useRef(0);diff --git a/src/types.ts b/src/types.tsindex 25cc7948..eb6b3e6e 100644--- a/src/types.ts+++ b/src/types.ts@@ -19,7 +19,7 @@ export interface StateSegment extends SegmentBase {}export interface Segment extends SegmentBase {- name?: string,+ name?: string | undefined,}export interface ApparentCutSegment extends ApparentSegmentBase {diff --git a/src/util.ts b/src/util.tsindex 046061cc..0df2293e 100644--- a/src/util.ts+++ b/src/util.ts@@ -44,16 +44,16 @@ function getFileBaseName(filePath?: string) {return parsed.name;}-export function getOutPath<T extends string | undefined>(a: { customOutDir?: string, filePath?: T, fileName: string }): T extends string ? string : undefined;-export function getOutPath({ customOutDir, filePath, fileName }: { customOutDir?: string, filePath?: string | undefined, fileName: string }) {+export function getOutPath<T extends string | undefined>(a: { customOutDir?: string | undefined, filePath?: T | undefined, fileName: string }): T extends string ? string : undefined;+export function getOutPath({ customOutDir, filePath, fileName }: { customOutDir?: string | undefined, filePath?: string | undefined, fileName: string }) {if (filePath == null) return undefined;return join(getOutDir(customOutDir, filePath), fileName);}export const getSuffixedFileName = (filePath: string | undefined, nameSuffix: string) => `${getFileBaseName(filePath)}-${nameSuffix}`;-export function getSuffixedOutPath<T extends string | undefined>(a: { customOutDir?: string, filePath?: T, nameSuffix: string }): T extends string ? string : undefined;-export function getSuffixedOutPath({ customOutDir, filePath, nameSuffix }: { customOutDir?: string, filePath?: string | undefined, nameSuffix: string }) {+export function getSuffixedOutPath<T extends string | undefined>(a: { customOutDir?: string | undefined, filePath?: T | undefined, nameSuffix: string }): T extends string ? string : undefined;+export function getSuffixedOutPath({ customOutDir, filePath, nameSuffix }: { customOutDir?: string | undefined, filePath?: string | undefined, nameSuffix: string }) {if (filePath == null) return undefined;return getOutPath({ customOutDir, filePath, fileName: getSuffixedFileName(filePath, nameSuffix) });}@@ -107,10 +107,11 @@ export async function dirExists(dirPath) {const testFailFsOperation = false;// Retry because sometimes write operations fail on windows due to the file being locked for various reasons (often anti-virus) #272 #1797 #1704-export async function fsOperationWithRetry(operation, { signal, retries = 10, minTimeout = 100, maxTimeout = 2000, ...opts }: Options & { retries?: number, minTimeout?: number, maxTimeout?: number } = {}) {+export async function fsOperationWithRetry(operation, { signal, retries = 10, minTimeout = 100, maxTimeout = 2000, ...opts }: Options & { retries?: number | undefined, minTimeout?: number | undefined, maxTimeout?: number | undefined } = {}) {return pRetry(async () => {if (testFailFsOperation && Math.random() > 0.3) throw Object.assign(new Error('test delete failure'), { code: 'EPERM' });await operation();+ // @ts-expect-error todo}, {retries,signal,@@ -391,7 +392,7 @@ function setDocumentExtraTitle(extra) {document.title = extra != null ? `${baseTitle} - ${extra}` : baseTitle;}-export function setDocumentTitle({ filePath, working, cutProgress }: { filePath?: string, working?: string, cutProgress?: number }) {+export function setDocumentTitle({ filePath, working, cutProgress }: { filePath?: string | undefined, working?: string | undefined, cutProgress?: number | undefined }) {const parts: string[] = [];if (filePath) parts.push(basename(filePath));if (working) {diff --git a/src/util/duration.ts b/src/util/duration.tsindex 9c010b75..ff805280 100644--- a/src/util/duration.ts+++ b/src/util/duration.ts@@ -1,7 +1,7 @@import padStart from 'lodash/padStart';export function formatDuration({ seconds: totalSecondsIn, fileNameFriendly, showFraction = true, shorten = false, fps }: {- seconds?: number, fileNameFriendly?: boolean, showFraction?: boolean, shorten?: boolean, fps?: number,+ seconds?: number | undefined, fileNameFriendly?: boolean | undefined, showFraction?: boolean | undefined, shorten?: boolean | undefined, fps?: number | undefined,}) {const totalSeconds = totalSecondsIn || 0;const totalSecondsAbs = Math.abs(totalSeconds);diff --git a/src/util/streams.ts b/src/util/streams.tsindex ac8906db..29f453a4 100644--- a/src/util/streams.ts+++ b/src/util/streams.ts@@ -111,7 +111,7 @@ export const isMov = (format: string) => ['ismv', 'ipod', 'mp4', 'mov'].includestype GetVideoArgsFn = (a: { streamIndex: number, outputIndex: number }) => string[] | undefined;function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposition = false, getVideoArgs = () => undefined }: {- stream, outputIndex: number, outFormat: string, manuallyCopyDisposition?: boolean, getVideoArgs?: GetVideoArgsFn+ stream, outputIndex: number, outFormat: string, manuallyCopyDisposition?: boolean | undefined, getVideoArgs?: GetVideoArgsFn | undefined}) {let args: string[] = [];diff --git a/tsconfig.web.json b/tsconfig.web.jsonindex 7ff0be43..72d6590e 100644--- a/tsconfig.web.json+++ b/tsconfig.web.json@@ -5,7 +5,6 @@"plugins": [{ "name": "typescript-plugin-css-modules" }],"noEmit": true,- "exactOptionalPropertyTypes": false, // todo"noImplicitAny": false, // todo"checkJs": false, // todo"allowJs": true, // todo