hamster-desktop/electron/ipcMainHandlers.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

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 13:46:02 +08:00
import {
findDcmFiles,
processFilesInBatches,
structureMetadata,
} from "./core/dicom";
2024-08-07 10:28:05 +08:00
import { EVENT_PARSE_DICOM } from "./ipcEvent";
2024-08-08 14:29:57 +08:00
import { cpuStartInfer } from "./core/infer/vino";
2024-08-05 16:50:11 +08:00
2024-08-06 16:59:49 +08:00
/**
*
*/
2024-08-07 13:46:02 +08:00
const registerIpcMainHandlers = (mainWindow: Electron.BrowserWindow | null) => {
if (!mainWindow) return;
2024-08-08 14:29:57 +08:00
2024-08-07 10:28:05 +08:00
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
});
2024-08-08 14:29:57 +08:00
ipcMain.handle("openvino", async (event, data) => {
cpuStartInfer();
});
2024-08-05 16:50:11 +08:00
};
export default registerIpcMainHandlers;