2024-09-23 13:02:38 +08:00
|
|
|
import { ipcMain, shell } from "electron";
|
2024-09-11 17:01:22 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|