diff --git a/README.md b/README.md index e654e89..f9ae2ff 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,6 @@ pnpm config set virtual-store-dir-max-length 70 ## 待解决 -- dicom导入后,本地appData建立一个拷贝区域,复制dicom原片,满足二次导出,防止原片的路径修改、移动硬盘被拔电源 \ No newline at end of file +- dicom导入后,本地appData建立一个拷贝区域,复制dicom原片,满足二次导出,防止原片的路径修改、移动硬盘被拔电源 + +- log 分模块记录日志,目前都在AppData/Romaing/@cvpilot/main.log 里面 \ No newline at end of file diff --git a/apps/desktop/electron/core/auth.ts b/apps/desktop/electron/core/auth.ts index c1d6518..53098f6 100644 --- a/apps/desktop/electron/core/auth.ts +++ b/apps/desktop/electron/core/auth.ts @@ -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); }; diff --git a/apps/desktop/electron/core/pacs.ts b/apps/desktop/electron/core/pacs.ts new file mode 100644 index 0000000..50f24ea --- /dev/null +++ b/apps/desktop/electron/core/pacs.ts @@ -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') + } +} \ No newline at end of file diff --git a/apps/desktop/electron/ipcEvent/dicom.ts b/apps/desktop/electron/ipcEvent/dicom.ts new file mode 100644 index 0000000..e6fb7a6 --- /dev/null +++ b/apps/desktop/electron/ipcEvent/dicom.ts @@ -0,0 +1,3 @@ +export const useDicomHandler = () => { + +} \ No newline at end of file diff --git a/apps/desktop/electron/ipcEvent/index.ts b/apps/desktop/electron/ipcEvent/index.ts index e69de29..5446510 100644 --- a/apps/desktop/electron/ipcEvent/index.ts +++ b/apps/desktop/electron/ipcEvent/index.ts @@ -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() +} \ No newline at end of file diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts index feac7bf..d6cc17d 100644 --- a/apps/desktop/electron/main.ts +++ b/apps/desktop/electron/main.ts @@ -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") { diff --git a/apps/desktop/shared/ipc.types.ts b/apps/desktop/shared/ipc.types.ts new file mode 100644 index 0000000..90de541 --- /dev/null +++ b/apps/desktop/shared/ipc.types.ts @@ -0,0 +1,9 @@ +/** + * ipc 通信的type、interface + */ +export namespace IPCEvents { + export enum Dicom { + Upload = 'dicom:upload', + Remove = 'dicom:remove', + } +} \ No newline at end of file diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json index 0bd9955..f45f246 100644 --- a/apps/desktop/tsconfig.json +++ b/apps/desktop/tsconfig.json @@ -32,7 +32,8 @@ }, "include": [ "src", - "electron" + "electron", + "shared" ], "references": [ {