cvpilot-tool/apps/desktop/electron/ipcEvent/common/index.ts

34 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

import { ipcMain, shell } from "electron";
import { mkdir, stat } from "fs/promises";
import { db } from "../../core/db";
import log from "electron-log";
import path from "node:path";
export const registerCommonHandler = () => {
ipcMain.handle("output:open", async () => {
await db.read();
const optPath = db.data.setting.outputPath;
const resolvedPath = path.resolve(optPath);
try {
// 检查路径是否存在
const stats = await stat(resolvedPath);
if (stats.isDirectory()) shell.openPath(resolvedPath);
} catch (error) {
log.error(error);
await mkdir(resolvedPath, { recursive: true });
shell.openPath(resolvedPath);
}
});
ipcMain.handle("device:infer:set", async (_event, inferDevice) => {
try {
await db.update(({ setting }) => ({ ...setting, inferDevice }));
return { success: true, msg: `推理硬件修改为${inferDevice}` };
} catch (error) {
await db.update(({ setting }) => ({ ...setting, inferDevice }));
log.error(error);
return { success: false, msg: `操作失败` };
}
});
};