feat: 调整orthanc注册 事件模块
This commit is contained in:
parent
a4a1198402
commit
348c9df6bc
|
@ -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 里面
|
|
@ -4,5 +4,5 @@ import { machineIdSync } from "node-machine-id";
|
||||||
|
|
||||||
export const getMachineId = async () => {
|
export const getMachineId = async () => {
|
||||||
const id = await machineIdSync();
|
const id = await machineIdSync();
|
||||||
console.warn("机器码id: ", id);
|
console.warn("machineId:", id);
|
||||||
};
|
};
|
||||||
|
|
26
apps/desktop/electron/core/pacs.ts
Normal file
26
apps/desktop/electron/core/pacs.ts
Normal 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')
|
||||||
|
}
|
||||||
|
}
|
3
apps/desktop/electron/ipcEvent/dicom.ts
Normal file
3
apps/desktop/electron/ipcEvent/dicom.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const useDicomHandler = () => {
|
||||||
|
|
||||||
|
}
|
|
@ -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()
|
||||||
|
}
|
|
@ -12,10 +12,8 @@ import path from "node:path";
|
||||||
import { createDatabase } from "./core/db";
|
import { createDatabase } from "./core/db";
|
||||||
import { getMachineId } from "./core/auth";
|
import { getMachineId } from "./core/auth";
|
||||||
import registerIpcMainHandlers from "./ipcMainHandlers";
|
import registerIpcMainHandlers from "./ipcMainHandlers";
|
||||||
import { spawn } from "node:child_process";
|
import { getPacsPath, runOrthancServer } from "./core/pacs";
|
||||||
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
||||||
import log from "electron-log";
|
|
||||||
import { existsSync } from "node:fs";
|
|
||||||
|
|
||||||
// const require = createRequire(import.meta.url);
|
// const require = createRequire(import.meta.url);
|
||||||
const __dirname = path.dirname(fileURLToPath(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 win: BrowserWindow | null;
|
||||||
let tray: Tray | null = null;
|
let tray: Tray | null = null;
|
||||||
let python_process: ChildProcessWithoutNullStreams | null = null;
|
|
||||||
const theme: "dark" | "light" = "light";
|
const theme: "dark" | "light" = "light";
|
||||||
|
|
||||||
const themeTitleBarStyles = {
|
const themeTitleBarStyles = {
|
||||||
|
@ -40,7 +37,7 @@ const themeTitleBarStyles = {
|
||||||
light: {},
|
light: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const platform = process.platform === "darwin" ? "macos" : "windows";
|
export const platform = process.platform === "darwin" ? "macos" : "windows";
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
|
@ -67,59 +64,30 @@ function createWindow() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 开发环境
|
||||||
if (VITE_DEV_SERVER_URL) {
|
if (VITE_DEV_SERVER_URL) {
|
||||||
win.loadURL(VITE_DEV_SERVER_URL);
|
win.loadURL(VITE_DEV_SERVER_URL);
|
||||||
registerIpcMainHandlers(win);
|
registerIpcMainHandlers(win);
|
||||||
|
runOrthancServer(getPacsPath(platform, true))
|
||||||
|
|
||||||
const pacsPath =
|
// if (platform !== "macos") {
|
||||||
platform !== "macos"
|
// python_process = spawn(path.join(process.env.VITE_PUBLIC!, "main.exe"));
|
||||||
? 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"));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// if (platform !== "macos") {
|
// if (platform !== "macos") {
|
||||||
// python_process = spawn(path.join(process.env.VITE_PUBLIC!, "main.exe"));
|
// 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(() => {
|
win.loadFile(path.join(RENDERER_DIST, "index.html")).then(() => {
|
||||||
|
registerIpcMainHandlers(win);
|
||||||
|
runOrthancServer(getPacsPath(platform, false))
|
||||||
|
|
||||||
|
// windows右键打开的目录路径
|
||||||
if (process.argv.length >= 2) {
|
if (process.argv.length >= 2) {
|
||||||
const folderPath = process.argv[2];
|
const folderPath = process.argv[2];
|
||||||
win?.webContents.send("context-menu-launch", folderPath);
|
win?.webContents.send("context-menu-launch", folderPath);
|
||||||
registerIpcMainHandlers(win);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -183,7 +151,7 @@ app.on("activate", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("before-quit", () => {
|
app.on("before-quit", () => {
|
||||||
console.log(python_process?.pid);
|
// console.log(python_process?.pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
|
@ -192,7 +160,7 @@ app.whenReady().then(() => {
|
||||||
createTray();
|
createTray();
|
||||||
registerGlobalShortcuts();
|
registerGlobalShortcuts();
|
||||||
createDatabase({ name: "cvpilot.json" });
|
createDatabase({ name: "cvpilot.json" });
|
||||||
console.log("userData路径:", path.join(app.getPath("userData")));
|
console.log("userData:", path.join(app.getPath("userData")));
|
||||||
|
|
||||||
// 设置 Dock 图标
|
// 设置 Dock 图标
|
||||||
if (platform === "macos") {
|
if (platform === "macos") {
|
||||||
|
|
9
apps/desktop/shared/ipc.types.ts
Normal file
9
apps/desktop/shared/ipc.types.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* ipc 通信的type、interface
|
||||||
|
*/
|
||||||
|
export namespace IPCEvents {
|
||||||
|
export enum Dicom {
|
||||||
|
Upload = 'dicom:upload',
|
||||||
|
Remove = 'dicom:remove',
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,8 @@
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src",
|
"src",
|
||||||
"electron"
|
"electron",
|
||||||
|
"shared"
|
||||||
],
|
],
|
||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user