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

52 lines
1.4 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();
});
};
export default registerIpcMainHandlers;