mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-24 23:05:49 +00:00
- Remove dead helperExists local in recording/windows.ts
- Hoist fs/promises import out of close handler in recording/ffmpeg.ts
- Guard fs.readdir with mkdir in recording/prune.ts (ENOENT resilience)
- Derive companion audio suffixes from COMPANION_AUDIO_LAYOUTS in prune.ts
- Guard mousemove hook registration to Linux only in cursor/interaction.ts
- Replace dynamic require('electron') with static import in cursor/monitor.ts
- Wrap nodeRequire in try/catch in ffmpeg/binary.ts for fallback safety
- Fix hardcoded timeOffsetMs: 0 in project/session.ts (use normalizer)
- Fix isPathInsideDirectory to normalize candidatePath in project/manager.ts
- Fix isAllowedLocalReadPath security: require path to be in allowlist (AND not OR)
- Derive extension regex from constants in project/manager.ts
- Consolidate duplicate Duration parsers in recording/diagnostics.ts
- Refactor ensureReadableFile to use options object instead of description string
- Make swiftc compilation async (execFile) in paths/binaries.ts
- Add socket timeout to httpsGet in captions/whisper.ts
81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { existsSync } from "node:fs";
|
|
import { createRequire } from "node:module";
|
|
import { app } from "electron";
|
|
|
|
const nodeRequire = createRequire(import.meta.url);
|
|
|
|
export function loadFfmpegStatic(): string | null {
|
|
try {
|
|
const moduleExports = nodeRequire("ffmpeg-static");
|
|
if (typeof moduleExports === "string") {
|
|
return moduleExports;
|
|
}
|
|
|
|
if (typeof moduleExports?.default === "string") {
|
|
return moduleExports.default as string;
|
|
}
|
|
} catch {
|
|
// ffmpeg-static not available; fall through to system FFmpeg
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function resolveSystemFfmpegBinaryPath(): string | null {
|
|
const locator = process.platform === "win32" ? "where" : "which";
|
|
const result = spawnSync(locator, ["ffmpeg"], {
|
|
encoding: "utf-8",
|
|
windowsHide: true,
|
|
});
|
|
|
|
if (result.status === 0) {
|
|
const candidate = result.stdout
|
|
.split(/\r?\n/)
|
|
.map((line: string) => line.trim())
|
|
.find((line: string) => line.length > 0);
|
|
|
|
if (candidate) {
|
|
return candidate;
|
|
}
|
|
}
|
|
|
|
// Fallback: check common install paths directly (Electron's shell may lack full PATH)
|
|
if (process.platform !== "win32") {
|
|
const commonPaths = [
|
|
"/opt/homebrew/bin/ffmpeg",
|
|
"/usr/local/bin/ffmpeg",
|
|
"/usr/bin/ffmpeg",
|
|
];
|
|
for (const p of commonPaths) {
|
|
if (existsSync(p)) {
|
|
return p;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function getFfmpegBinaryPath(): string {
|
|
const ffmpegStatic = loadFfmpegStatic();
|
|
if (ffmpegStatic && typeof ffmpegStatic === "string") {
|
|
const bundledPath = app.isPackaged
|
|
? ffmpegStatic.replace(/\.asar([/\\])/, ".asar.unpacked$1")
|
|
: ffmpegStatic;
|
|
|
|
if (existsSync(bundledPath)) {
|
|
return bundledPath;
|
|
}
|
|
}
|
|
|
|
const systemFfmpeg = resolveSystemFfmpegBinaryPath();
|
|
if (systemFfmpeg) {
|
|
return systemFfmpeg;
|
|
}
|
|
|
|
throw new Error(
|
|
"FFmpeg binary is unavailable. Install ffmpeg-static for this platform or make ffmpeg available on PATH.",
|
|
);
|
|
}
|