feat: 调整orthanc注册 事件模块

This commit is contained in:
mozzie 2024-09-10 22:03:12 +08:00
parent a4a1198402
commit 348c9df6bc
8 changed files with 72 additions and 50 deletions

View File

@ -13,4 +13,6 @@ pnpm config set virtual-store-dir-max-length 70
## 待解决
- dicom导入后本地appData建立一个拷贝区域复制dicom原片满足二次导出防止原片的路径修改、移动硬盘被拔电源
- dicom导入后本地appData建立一个拷贝区域复制dicom原片满足二次导出防止原片的路径修改、移动硬盘被拔电源
- log 分模块记录日志目前都在AppData/Romaing/@cvpilot/main.log 里面

View File

@ -4,5 +4,5 @@ import { machineIdSync } from "node-machine-id";
export const getMachineId = async () => {
const id = await machineIdSync();
console.warn("机器码id: ", id);
console.warn("machineId:", id);
};

View File

@ -0,0 +1,26 @@
import { spawn } from "node:child_process";
import { existsSync } from "node:fs";
import log from 'electron-log'
import path from "node:path";
export const getPacsPath = (platform: "macos" | "windows", isDevelopment: boolean): string => {
const orthancExecFile = {
macos: "orthanc-mac-24.8.1/Orthanc",
windows: "orthanc-win64-1.12.4/Orthanc.exe"
}
const basePath = isDevelopment
? path.join(process.env.VITE_PUBLIC, "../extraResources")
: path.join(process.resourcesPath, 'lib');
return path.join(basePath, orthancExecFile[platform])
}
export const runOrthancServer = (pacsPath: string) => {
if (existsSync(pacsPath)) {
const child_process = spawn(pacsPath)
child_process.stdout.on('data', data => log.info(data))
// child_process.stderr.on('data', data => log.error(data))
} else {
console.error('pacsPath is a not exist')
log.error('pacsPath is a not exist')
}
}

View File

@ -0,0 +1,3 @@
export const useDicomHandler = () => {
}

View File

@ -0,0 +1,13 @@
import { ipcMain } from "electron";
import { useDicomHandler } from "./dicom";
export const registerIpcMainHandlers = (mainWindow: Electron.BrowserWindow) => {
ipcMain.removeAllListeners();
/**
*
*/
ipcMain.on("ipc-loaded", () => mainWindow.show());
useDicomHandler()
}

View File

@ -12,10 +12,8 @@ import path from "node:path";
import { createDatabase } from "./core/db";
import { getMachineId } from "./core/auth";
import registerIpcMainHandlers from "./ipcMainHandlers";
import { spawn } from "node:child_process";
import { ChildProcessWithoutNullStreams } from "child_process";
import log from "electron-log";
import { existsSync } from "node:fs";
import { getPacsPath, runOrthancServer } from "./core/pacs";
// const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@ -32,7 +30,6 @@ process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
let win: BrowserWindow | null;
let tray: Tray | null = null;
let python_process: ChildProcessWithoutNullStreams | null = null;
const theme: "dark" | "light" = "light";
const themeTitleBarStyles = {
@ -40,7 +37,7 @@ const themeTitleBarStyles = {
light: {},
};
const platform = process.platform === "darwin" ? "macos" : "windows";
export const platform = process.platform === "darwin" ? "macos" : "windows";
function createWindow() {
win = new BrowserWindow({
@ -67,59 +64,30 @@ function createWindow() {
});
});
// 开发环境
if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL);
registerIpcMainHandlers(win);
runOrthancServer(getPacsPath(platform, true))
const pacsPath =
platform !== "macos"
? path.join(
process.env.APP_ROOT!,
"extraResources",
"orthanc-win64-1.12.4",
"Orthanc.exe"
)
: path.join(
process.env.APP_ROOT!,
"extraResources",
"orthanc-mac-24.8.1",
"Orthanc"
);
spawn(pacsPath);
if (platform !== "macos") {
python_process = spawn(path.join(process.env.VITE_PUBLIC!, "main.exe"));
}
// if (platform !== "macos") {
// python_process = spawn(path.join(process.env.VITE_PUBLIC!, "main.exe"));
// }
} else {
// if (platform !== "macos") {
// python_process = spawn(path.join(process.env.VITE_PUBLIC!, "main.exe"));
// }
const pacsPath =
platform !== "macos"
? path.join(
process.resourcesPath,
"lib",
"orthanc-win64-1.12.4",
"Orthanc.exe"
)
: path.join(
process.resourcesPath,
"lib",
"orthanc-mac-24.8.1",
"Orthanc"
);
console.log(pacsPath);
log.info(pacsPath);
if (existsSync(pacsPath)) spawn(pacsPath);
win.loadFile(path.join(RENDERER_DIST, "index.html")).then(() => {
registerIpcMainHandlers(win);
runOrthancServer(getPacsPath(platform, false))
// windows右键打开的目录路径
if (process.argv.length >= 2) {
const folderPath = process.argv[2];
win?.webContents.send("context-menu-launch", folderPath);
registerIpcMainHandlers(win);
}
});
}
@ -183,7 +151,7 @@ app.on("activate", () => {
});
app.on("before-quit", () => {
console.log(python_process?.pid);
// console.log(python_process?.pid);
});
app.whenReady().then(() => {
@ -192,7 +160,7 @@ app.whenReady().then(() => {
createTray();
registerGlobalShortcuts();
createDatabase({ name: "cvpilot.json" });
console.log("userData路径:", path.join(app.getPath("userData")));
console.log("userData:", path.join(app.getPath("userData")));
// 设置 Dock 图标
if (platform === "macos") {

View File

@ -0,0 +1,9 @@
/**
* ipc typeinterface
*/
export namespace IPCEvents {
export enum Dicom {
Upload = 'dicom:upload',
Remove = 'dicom:remove',
}
}

View File

@ -32,7 +32,8 @@
},
"include": [
"src",
"electron"
"electron",
"shared"
],
"references": [
{