hamster-desktop/electron/ipcMainHandlers.ts

28 lines
967 B
TypeScript
Raw Normal View History

2024-08-05 16:50:11 +08:00
import path from "path";
2024-08-07 10:28:05 +08:00
import { dialog, ipcMain } from "electron";
2024-08-06 09:44:11 +08:00
import os from "os";
2024-08-07 10:28:05 +08:00
import { findDcmFiles, processFilesInBatches, structureMetadata } from "./core/dicom";
import { EVENT_PARSE_DICOM } from "./ipcEvent";
2024-08-05 16:50:11 +08:00
2024-08-06 16:59:49 +08:00
/**
*
*/
2024-08-07 10:28:05 +08:00
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);
}
2024-08-05 16:50:11 +08:00
});
};
export default registerIpcMainHandlers;