Skip to content

Commit c17c413

Browse files
committed
fix: use utilityProcess on all platforms for frontend startup
spawn('node') doesn't work in packaged builds since there's no system node. Revert to utilityProcess.fork() everywhere and pass process.env so Windows gets the system vars it needs.
1 parent 63ab28a commit c17c413

2 files changed

Lines changed: 19 additions & 50 deletions

File tree

apps/desktop/electron/process-manager.ts

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -185,55 +185,24 @@ export class ProcessManager {
185185
};
186186

187187
if (usePacked) {
188-
// macOS: utilityProcess 不在 Dock 显示图标; Windows: spawn 更稳定
189-
if (process.platform === 'win32') {
190-
this.logger.info(`Starting frontend (spawn): node ${serverJs}`);
191-
const procEnv = {
192-
...process.env,
193-
...env,
194-
NODE_PATH: path.join(nextDir, 'node_modules'),
195-
};
196-
this.frontendProcess = spawn('node', [serverJs], {
197-
cwd: nextDir,
198-
env: procEnv,
199-
stdio: ['ignore', 'pipe', 'pipe'],
200-
detached: false,
201-
shell: false,
202-
});
203-
this.frontendProcess.stdout?.on('data', (data) => {
204-
this.logger.debug(`[Frontend] ${data.toString().trim()}`);
205-
});
206-
this.frontendProcess.stderr?.on('data', (data) => {
207-
this.logger.debug(`[Frontend] ${data.toString().trim()}`);
208-
});
209-
this.frontendProcess.on('error', (error) => {
210-
this.logger.error('Frontend process error', error);
211-
});
212-
this.frontendProcess.on('exit', (code) => {
213-
if (code !== 0) {
214-
this.logger.warn(`Frontend exited with code ${code}`);
215-
}
216-
});
217-
} else {
218-
this.logger.info(`Starting frontend (utilityProcess): ${serverJs}`);
219-
const up = utilityProcess.fork(serverJs, [], {
220-
cwd: nextDir,
221-
env,
222-
stdio: 'pipe',
223-
});
224-
up.stdout?.on('data', (data: Buffer) => {
225-
this.logger.debug(`[Frontend] ${data.toString().trim()}`);
226-
});
227-
up.stderr?.on('data', (data: Buffer) => {
228-
this.logger.debug(`[Frontend] ${data.toString().trim()}`);
229-
});
230-
up.on('exit', (code) => {
231-
if (code !== 0) {
232-
this.logger.warn(`Frontend exited with code ${code}`);
233-
}
234-
});
235-
this.frontendProcess = up as unknown as ChildProcess;
236-
}
188+
this.logger.info(`Starting frontend (utilityProcess): ${serverJs}`);
189+
const up = utilityProcess.fork(serverJs, [], {
190+
cwd: nextDir,
191+
env: { ...process.env, ...env },
192+
stdio: 'pipe',
193+
});
194+
up.stdout?.on('data', (data: Buffer) => {
195+
this.logger.debug(`[Frontend] ${data.toString().trim()}`);
196+
});
197+
up.stderr?.on('data', (data: Buffer) => {
198+
this.logger.debug(`[Frontend] ${data.toString().trim()}`);
199+
});
200+
up.on('exit', (code) => {
201+
if (code !== 0) {
202+
this.logger.warn(`Frontend exited with code ${code}`);
203+
}
204+
});
205+
this.frontendProcess = up as unknown as ChildProcess;
237206
} else {
238207
// 开发模式:用 next start
239208
this.logger.info('Starting frontend (dev mode): next start');

apps/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "querygpt-desktop",
3-
"version": "0.1.1",
3+
"version": "0.1.0",
44
"description": "QueryGPT Desktop Application",
55
"main": "dist-electron/main.js",
66
"author": "QueryGPT Team",

0 commit comments

Comments
 (0)