ref: better import for utils
fix: inappropriate ffmpeg path in `immediatelyExtractFrameFromVideo()`
This commit is contained in:
parent
38185cc969
commit
a0a90f2428
@ -41,6 +41,7 @@
|
||||
"image-size": "^1.1.1",
|
||||
"jotai": "^2.11.0",
|
||||
"memory-cache": "^0.2.0",
|
||||
"pino": "^9.6.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-i18next": "^15.1.2",
|
||||
|
@ -4,8 +4,8 @@ import fs from "fs";
|
||||
import path, { join } from "path";
|
||||
import type { EncodingTask, Frame } from "./schema";
|
||||
import sizeOf from "image-size";
|
||||
import { getEncodeCommand } from "../utils/video/index.js";
|
||||
import { getRecordingsDir, getEncodingTempDir, getScreenshotsDir } from "../utils/fs/index.js";
|
||||
import { getEncodeCommand } from "../utils/index.js";
|
||||
import { getRecordingsDir, getEncodingTempDir, getScreenshotsDir } from "../utils/index.js";
|
||||
import cache from "memory-cache";
|
||||
import { ENCODING_FRAME_INTERVAL, RECORD_FRAME_RATE as FRAME_RATE } from "./consts.js";
|
||||
|
||||
|
@ -2,7 +2,7 @@ import * as path from "path";
|
||||
import { Database } from "better-sqlite3";
|
||||
import DB from "better-sqlite3";
|
||||
import { __dirname } from "../dirname.js";
|
||||
import { getDatabaseDir } from "../utils/fs/index.js";
|
||||
import { getDatabaseDir } from "../utils/index.js";
|
||||
import { migrate } from "./migrate/index.js";
|
||||
|
||||
function getLibSimpleExtensionPath() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import screenshot from "screenshot-desktop";
|
||||
import { getScreenshotsDir } from "../utils/fs/index.js";
|
||||
import { getScreenshotsDir } from "../utils/index.js";
|
||||
import { join } from "path";
|
||||
import { Database } from "better-sqlite3";
|
||||
import SqlString from "sqlstring";
|
||||
|
@ -2,7 +2,7 @@ import { app, BrowserWindow, screen } from "electron";
|
||||
import { join } from "path";
|
||||
import { __dirname } from "./dirname.js";
|
||||
import windowStateManager from "electron-window-state";
|
||||
import { hideDock, showDock } from "./utils/platform/index.js";
|
||||
import { hideDock, showDock } from "./utils/index.js";
|
||||
|
||||
function loadURL(window: BrowserWindow, path = "", vitePort: string) {
|
||||
const dev = !app.isPackaged;
|
||||
|
@ -16,7 +16,7 @@ import { initDatabase } from "./backend/init.js";
|
||||
import { Database } from "better-sqlite3";
|
||||
import { startScreenshotLoop } from "./backend/screenshot.js";
|
||||
import { __dirname } from "./dirname.js";
|
||||
import { hideDock } from "./utils/platform/index.js";
|
||||
import { hideDock } from "./utils/index.js";
|
||||
import {
|
||||
checkFramesForEncoding,
|
||||
deleteUnnecessaryScreenshots,
|
||||
@ -24,7 +24,7 @@ import {
|
||||
} from "./backend/encoding.js";
|
||||
import honoApp from "./server/index.js";
|
||||
import { serve } from "@hono/node-server";
|
||||
import { findAvailablePort } from "./utils/network/index.js";
|
||||
import { findAvailablePort } from "./utils/index.js";
|
||||
import cache from "memory-cache";
|
||||
import { generate as generateAPIKey } from "@alikia/random-key";
|
||||
|
||||
|
@ -10,8 +10,8 @@ import {
|
||||
getRecordingsDir,
|
||||
getScreenshotsDir,
|
||||
waitForFileExists
|
||||
} from "../utils/fs/index.js";
|
||||
import { immediatelyExtractFrameFromVideo } from "../utils/video/index.js";
|
||||
} from "../utils/index.js";
|
||||
import { immediatelyExtractFrameFromVideo } from "../utils/index.js";
|
||||
import { existsSync } from "fs";
|
||||
|
||||
const app = new Hono();
|
||||
|
@ -59,6 +59,15 @@ export function getDecodingTempDir() {
|
||||
return decodingTempDir;
|
||||
}
|
||||
|
||||
export function getLogDir() {
|
||||
const dataDir = createDataDir();
|
||||
const logDir = path.join(dataDir, "logs");
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir, { recursive: true });
|
||||
}
|
||||
return logDir;
|
||||
}
|
||||
|
||||
export async function waitForFileExists(filePath: string, timeout: number = 10000): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.access(filePath, fs.constants.F_OK, (err) => {
|
||||
|
@ -2,3 +2,4 @@ export * from "./fs/index.js";
|
||||
export * from "./platform/index.js";
|
||||
export * from "./video/index.js";
|
||||
export * from "./network/index.js";
|
||||
export * from "./logging/index.js";
|
10
src/electron/utils/logging/index.ts
Normal file
10
src/electron/utils/logging/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import pino from "pino";
|
||||
import { join } from "path";
|
||||
import { getLogDir } from "../fs/index.js";
|
||||
|
||||
const logPath = join(getLogDir(), "log.json");
|
||||
const dest = pino.destination(logPath);
|
||||
|
||||
const logger = pino(dest);
|
||||
|
||||
export { logger };
|
@ -1,14 +1,15 @@
|
||||
import path from "path";
|
||||
import { join } from "path";
|
||||
import os from "os";
|
||||
import { app } from "electron";
|
||||
import { __dirname } from "../../dirname.js";
|
||||
import { logger } from "../index.js";
|
||||
|
||||
export function getUserDataDir() {
|
||||
switch (process.platform) {
|
||||
case "win32":
|
||||
return path.join(process.env.APPDATA!, "OpenRewind", "Record Data");
|
||||
return join(process.env.APPDATA!, "OpenRewind", "Record Data");
|
||||
case "darwin":
|
||||
return path.join(
|
||||
return join(
|
||||
os.homedir(),
|
||||
"Library",
|
||||
"Application Support",
|
||||
@ -16,7 +17,7 @@ export function getUserDataDir() {
|
||||
"Record Data"
|
||||
);
|
||||
case "linux":
|
||||
return path.join(os.homedir(), ".config", "OpenRewind", "Record Data");
|
||||
return join(os.homedir(), ".config", "OpenRewind", "Record Data");
|
||||
default:
|
||||
throw new Error("Unsupported platform");
|
||||
}
|
||||
@ -37,14 +38,20 @@ export function showDock() {
|
||||
}
|
||||
|
||||
export function getFFmpegPath() {
|
||||
let path = "";
|
||||
switch (process.platform) {
|
||||
case "win32":
|
||||
return path.join(__dirname, "bin", process.platform, "ffmpeg.exe");
|
||||
path = join(__dirname, "bin", process.platform, "ffmpeg.exe");
|
||||
break;
|
||||
case "darwin":
|
||||
return path.join(__dirname, "bin", process.platform, "ffmpeg");
|
||||
path = join(__dirname, "bin", process.platform, "ffmpeg");
|
||||
break;
|
||||
case "linux":
|
||||
return path.join(__dirname, "bin", process.platform, "ffmpeg");
|
||||
path = join(__dirname, "bin", process.platform, "ffmpeg");
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unsupported platform");
|
||||
}
|
||||
logger.info("FFmpeg path: %s", path);
|
||||
return path;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export function immediatelyExtractFrameFromVideo(
|
||||
"1",
|
||||
`${outputPathArg}`
|
||||
];
|
||||
const ffmpeg = spawn("ffmpeg", args);
|
||||
const ffmpeg = spawn(getFFmpegPath(), args);
|
||||
ffmpeg.stdout.on("data", (data) => {
|
||||
console.log(data.toString());
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user