52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
|
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;
|