hamster-desktop/electron/ipcMainHandlers.ts
2024-08-07 10:28:05 +08:00

28 lines
967 B
TypeScript

import path from "path";
import { dialog, ipcMain } from "electron";
import os from "os";
import { findDcmFiles, processFilesInBatches, structureMetadata } from "./core/dicom";
import { EVENT_PARSE_DICOM } from "./ipcEvent";
/**
* 渲染进程和主进程的事件调度
*/
const registerIpcMainHandlers = (mainWindow) => {
ipcMain.on(EVENT_PARSE_DICOM, async (event, file: string) => {
const dirDialog = await dialog.showOpenDialog(mainWindow, {
properties: ["openDirectory"],
});
if (dirDialog.filePaths.length > 0) {
const filePaths = await findDcmFiles(dirDialog.filePaths[0]);
const batchSize = os.cpus().length * 1 || 10;
console.time("分批处理");
const unraw = await processFilesInBatches(filePaths, batchSize);
console.timeEnd("分批处理");
const result = structureMetadata(unraw);
event.reply(EVENT_PARSE_DICOM + ":RES", result);
}
});
};
export default registerIpcMainHandlers;