The swiss army knife of lossless video/audio editing
Type-check the preload script, and fix small review findings
Claude4c7a4eca6f02
diff --git a/.gitignore b/.gitignoreindex 00ae7409..60827390 100644--- a/.gitignore+++ b/.gitignore@@ -18,6 +18,7 @@ node_modules/ffmpeg/app*.log/main-ts-dist+/preload-ts-dist/common-ts-disttsconfig.*.tsbuildinfo\ No newline at end of filediff --git a/.oxlintrc.json b/.oxlintrc.jsonindex 78c3fcfd..864ae14a 100644--- a/.oxlintrc.json+++ b/.oxlintrc.json@@ -8,6 +8,7 @@"dist","out","main-ts-dist",+ "preload-ts-dist","common-ts-dist","website/dist","website/.wrangler",diff --git a/package.json b/package.jsonindex 232c6f37..1ef083ca 100644--- a/package.json+++ b/package.json@@ -9,7 +9,7 @@"homepage": "./","type": "module","scripts": {- "clean": "rimraf dist out common-ts-dist main-ts-dist build-resources icon-build",+ "clean": "rimraf dist out common-ts-dist main-ts-dist preload-ts-dist build-resources icon-build","start": "electron-vite preview","dev": "electron-vite dev -w","download-ffmpeg-darwin-x64": "node script/downloadFfmpeg.ts darwin-x64",diff --git a/src/main/ffmpeg.ts b/src/main/ffmpeg.tsindex 1e4e40fd..dd805c58 100644--- a/src/main/ffmpeg.ts+++ b/src/main/ffmpeg.ts@@ -37,7 +37,6 @@ export function setCustomFfPath(path: string | undefined) {}function escapeCliArg(arg: string) {- // todo change String(arg) => arg when ts no-implicit-any is turned onif (isWindows) {// https://github.com/mifi/lossless-cut/issues/2151return /[\s"&<>^|]/.test(arg) ? `"${arg.replaceAll('"', '""')}"` : arg;@@ -290,14 +289,8 @@ export function mapTimesToSegments(times: number[], includeLast: boolean) {for (let i = 0; i < times.length; i += 1) {const start = times[i];const end = times[i + 1];- if (start != null) {- if (end != null) {- segments.push({ start, end });- // eslint-disable-next-line unicorn-js/no-duplicate-if-branches -- TODO fix (new rule in @mifi/lint-config)- } else if (includeLast) {- segments.push({ start, end }); // end undefined is allowed (means until end of video)- }- }+ // end undefined is allowed for the last segment (means until end of video)+ if (start != null && (end != null || includeLast)) segments.push({ start, end });}return segments;}diff --git a/src/renderer/src/BottomBar.tsx b/src/renderer/src/BottomBar.tsxindex e2c52d41..b5e7aae8 100644--- a/src/renderer/src/BottomBar.tsx+++ b/src/renderer/src/BottomBar.tsx@@ -33,8 +33,7 @@ import type { Frame } from './ffmpeg';import mainApi from './mainApi';-// eslint-disable-next-line unicorn-js/no-array-from-fill -- TODO fix (new rule in @mifi/lint-config)-const zoomOptions = Array.from({ length: 13 }).fill(undefined).map((_unused, z) => 2 ** z);+const zoomOptions = Array.from({ length: 13 }, (_unused, z) => 2 ** z);const leftRightWidth = 100;diff --git a/src/renderer/src/edlStore.ts b/src/renderer/src/edlStore.tsindex 0c1f25bb..f12dd665 100644--- a/src/renderer/src/edlStore.ts+++ b/src/renderer/src/edlStore.ts@@ -201,11 +201,7 @@ export async function exportEdlFile({ type, cutSegments, customOutDir, filePath,} else if (type === 'tsv-human') {ext = 'tsv';filters = [{ name: i18n.t('TXT files'), extensions: [ext, 'txt'] }];- } else if (type === 'csv-human') {- ext = 'csv';- filters = [{ name: i18n.t('TXT files'), extensions: [ext, 'txt'] }];- // eslint-disable-next-line unicorn-js/no-duplicate-if-branches -- TODO fix (new rule in @mifi/lint-config)- } else if (type === 'csv-frames') {+ } else if (type === 'csv-human' || type === 'csv-frames') {ext = 'csv';filters = [{ name: i18n.t('TXT files'), extensions: [ext, 'txt'] }];} else if (type === 'srt') {diff --git a/src/renderer/src/ffmpeg.ts b/src/renderer/src/ffmpeg.tsindex 0047261c..15cabe26 100644--- a/src/renderer/src/ffmpeg.ts+++ b/src/renderer/src/ffmpeg.ts@@ -164,15 +164,7 @@ export function getSafeCutTime(frames: Frame[], cutTime: number, nextMode: boolereturn time;}- // eslint-disable-next-line unicorn-js/no-unnecessary-parameters -- TODO fix (new rule in @mifi/lint-config)- const findReverseIndex = <T>(arr: T[], cb: (value: T, i: number, obj: T[]) => unknown) => {- // eslint-disable-next-line unicorn/no-array-callback-reference, unicorn-js/prefer-array-last-methods -- TODO fix (new rule in @mifi/lint-config)- const ret = arr.toReversed().findIndex(cb);- if (ret === -1) return -1;- return arr.length - 1 - ret;- };-- index = findReverseIndex(frames, (f) => f.time <= cutTime + sigma);+ index = frames.findLastIndex((f) => f.time <= cutTime + sigma);if (index === -1) throw new UserFacingError(i18n.t('Failed to find any prev frame'));if (index === 0) throw new UserFacingError(i18n.t('We are on the first frame'));@@ -186,7 +178,7 @@ export function getSafeCutTime(frames: Frame[], cutTime: number, nextMode: boole}// We are not on a frame before keyframe, look for preceding keyframe instead- index = findReverseIndex(frames, (f) => f.keyframe && f.time <= cutTime + sigma);+ index = frames.findLastIndex((f) => f.keyframe && f.time <= cutTime + sigma);if (index === -1) throw new UserFacingError(i18n.t('Failed to find any prev keyframe'));if (index === 0) throw new UserFacingError(i18n.t('We are on the first keyframe'));@@ -430,8 +422,7 @@ export async function renderThumbnails({ filePath, from, duration, onThumbnail,signal: AbortSignal,}) {const numThumbs = 10;- // eslint-disable-next-line unicorn-js/no-array-from-fill -- TODO fix (new rule in @mifi/lint-config)- const thumbTimes = Array.from({ length: numThumbs }).fill(undefined).map((_unused, i) => (from + ((duration * i) / numThumbs)));+ const thumbTimes = Array.from({ length: numThumbs }, (_unused, i) => (from + ((duration * i) / numThumbs)));// console.log(thumbTimes);await pMap(thumbTimes, async (time) => {@@ -444,8 +435,7 @@ export async function extractWaveform({ filePath, outPath }: { filePath: string,const numSegs = 10;const duration = 60 * 60;const maxLen = 0.1;- // eslint-disable-next-line unicorn-js/no-array-from-fill -- TODO fix (new rule in @mifi/lint-config)- const segments = Array.from({ length: numSegs }).fill(undefined).map((_unused, i) => [i * (duration / numSegs), Math.min(duration / numSegs, maxLen)] as const);+ const segments = Array.from({ length: numSegs }, (_unused, i) => [i * (duration / numSegs), Math.min(duration / numSegs, maxLen)] as const);// https://superuser.com/questions/681885/how-can-i-remove-multiple-segments-from-a-video-using-ffmpeglet filter = segments.map(([from, len], i) => `[0:a]atrim=start=${from}:end=${from + len},asetpts=PTS-STARTPTS[a${i}]`).join(';');diff --git a/src/renderer/src/hooks/useTimelineScroll.ts b/src/renderer/src/hooks/useTimelineScroll.tsindex 8637de00..f3b95c6b 100644--- a/src/renderer/src/hooks/useTimelineScroll.ts+++ b/src/renderer/src/hooks/useTimelineScroll.ts@@ -31,10 +31,10 @@ function useIsCtrlHeldRef() {window.addEventListener('pointerdown', onEvent, { capture: true });window.addEventListener('blur', onBlur);return () => {- window.removeEventListener('keydown', onEvent, true);- window.removeEventListener('keyup', onEvent, true);- window.removeEventListener('pointermove', onEvent, true);- window.removeEventListener('pointerdown', onEvent, true);+ window.removeEventListener('keydown', onEvent, { capture: true });+ window.removeEventListener('keyup', onEvent, { capture: true });+ window.removeEventListener('pointermove', onEvent, { capture: true });+ window.removeEventListener('pointerdown', onEvent, { capture: true });window.removeEventListener('blur', onBlur);};}, []);diff --git a/tsconfig.json b/tsconfig.jsonindex d45c9519..7250b88e 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -2,6 +2,7 @@"references": [{ "path": "./tsconfig.web.json" },{ "path": "./tsconfig.main.json" },+ { "path": "./tsconfig.preload.json" },{ "path": "./tsconfig.node.json" },{ "path": "./tsconfig.common.json" },],diff --git a/tsconfig.preload.json b/tsconfig.preload.jsonnew file mode 100644index 00000000..af07d665--- /dev/null+++ b/tsconfig.preload.json@@ -0,0 +1,19 @@+{+ "extends": "./tsconfig.main.json",+ "compilerOptions": {+ "outDir": "preload-ts-dist",+ "tsBuildInfoFile": "preload-ts-dist/tsconfig.tsbuildinfo",++ // the preload script runs in the renderer's window, with access to Node.js+ "lib": ["ES2024", "DOM"],+ "types": ["node"],+ // bundled by electron-vite, so nothing needs rewriting (and the import of src/main types would otherwise be TS2878)+ "rewriteRelativeImportExtensions": false,+ },+ "references": [+ { "path": "./tsconfig.main.json" },+ ],+ "include": [+ "src/preload/**/*",+ ],+}