import { app, 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"; import { getMetadata, getTotalScanLength } from "../../core/pacs"; import { InferStructuralEnum } from "../../core/alg.type"; import { readFileSync, statSync } from "fs"; 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("measure:excel", async (_event, SeriesInstanceUID) => { const excelPath = path.join( app.getPath("userData"), "output", SeriesInstanceUID ); try { if (statSync(excelPath).isDirectory()) { shell.openPath(excelPath); return { code: 1 }; } } catch (error) { return { code: 0, msg: "请先进行AI推理" }; } }); ipcMain.handle("measure:json", async (_event, SeriesInstanceUID) => { // 读取测量json const physicalLength = await getTotalScanLength(SeriesInstanceUID); const module = physicalLength && physicalLength < 200 ? InferStructuralEnum.AORTA : InferStructuralEnum.PERI; // 获取metadata if (module !== InferStructuralEnum.AORTA) return { code: 0, msg: "仅开放根部测量报告" }; const tags = await getMetadata(SeriesInstanceUID); const rootPath = path.join( app.getPath("userData"), "output", SeriesInstanceUID ); const measurementPath = path.join(rootPath, module, "measurement.json"); if (statSync(measurementPath).isFile()) { const measurement = readFileSync(measurementPath, "utf-8"); return { measurement: JSON.parse(measurement), tags }; } else { return { code: 0, msg: "请先进行AI推理" }; } }); };