diff --git a/desktop/src/main.ts b/desktop/src/main.ts index 5012deb..9bc513a 100644 --- a/desktop/src/main.ts +++ b/desktop/src/main.ts @@ -23,20 +23,18 @@ function createIcon(size = 32): Electron.NativeImage { let backend: ChildProcess | null = null function startBackend(): void { - const tsx = path.join(PROJECT_DIR, 'node_modules', 'tsx', 'dist', 'cli.mjs') - const node = process.execPath // Use Electron's bundled Node.js + broadcastLog('[后端] 正在启动...') - backend = spawn(node, [tsx, 'src/index.ts'], { + backend = spawn('npx', ['tsx', 'src/index.ts'], { cwd: PROJECT_DIR, stdio: ['ignore', 'pipe', 'pipe'], - env: { - ...process.env, - PORT: '3000', - SKIP_PLC: '1', - }, + env: { ...process.env, PORT: '3000', SKIP_PLC: '1' }, + shell: process.platform === 'win32', // Windows 需要 shell 运行 .cmd 文件 windowsHide: true, }) + backend.on('error', (err) => broadcastLog(`[后端] 启动失败: ${err.message}`)) + backend.stdout?.on('data', (d: Buffer) => { for (const line of d.toString().split('\n').filter(Boolean)) broadcastLog(line) })