cvpilot-tool/apps/desktop/electron/ipcMainHandlers.ts

67 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-08-29 16:59:25 +08:00
import { dialog, ipcMain } from "electron";
import os from "os";
import {
findDcmFiles,
processFilesInBatches,
structureMetadata,
} from "./core/dicom";
import { EVENT_PARSE_DICOM } from "./ipcEvent";
import PythonManager from "./core/PythonManager";
/**
*
*/
const registerIpcMainHandlers = (
mainWindow: Electron.BrowserWindow | null,
pythonManager: PythonManager
) => {
if (!mainWindow) return;
ipcMain.removeAllListeners();
/**
*
*/
ipcMain.on("ipc-loaded", () => mainWindow.show());
/**
* dicoM
*/
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);
}
});
ipcMain.on("python-service", (event, data) => {
const { running } = data;
running ? pythonManager.startFlask() : pythonManager.stopFlask();
});
2024-08-30 16:58:44 +08:00
ipcMain.on("scan-dicom", async (event) => {
2024-08-30 16:58:44 +08:00
const result = await dialog.showOpenDialog({
properties: ["openDirectory"],
});
if (result.canceled) return null;
const filePaths = result.filePaths[0];
const dcmPaths = await findDcmFiles(filePaths)
const batchSize = os.cpus().length * 1 || 10;
const items = await processFilesInBatches(dcmPaths, batchSize);
const structDicom = await structureMetadata(items, (progress) => {
event.reply('scan-progress', progress)
});
event.reply('scan-progress-done', structDicom)
2024-08-30 16:58:44 +08:00
});
2024-08-29 16:59:25 +08:00
};
export default registerIpcMainHandlers;