mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 08:33:36 +00:00
Merge pull request #326 from andydataguy/fix/windows-orphaned-server-processes
fix(windows): properly kill server process tree on app quit
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { spawn, ChildProcess } from 'child_process';
|
import { spawn, execSync, ChildProcess } from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import http, { Server } from 'http';
|
import http, { Server } from 'http';
|
||||||
@@ -595,9 +595,20 @@ app.on('window-all-closed', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on('before-quit', () => {
|
app.on('before-quit', () => {
|
||||||
if (serverProcess) {
|
if (serverProcess && serverProcess.pid) {
|
||||||
console.log('[Electron] Stopping server...');
|
console.log('[Electron] Stopping server...');
|
||||||
serverProcess.kill();
|
if (process.platform === 'win32') {
|
||||||
|
try {
|
||||||
|
// Windows: use taskkill with /t to kill entire process tree
|
||||||
|
// This prevents orphaned node processes when closing the app
|
||||||
|
// Using execSync to ensure process is killed before app exits
|
||||||
|
execSync(`taskkill /f /t /pid ${serverProcess.pid}`, { stdio: 'ignore' });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Electron] Failed to kill server process:', (error as Error).message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
serverProcess.kill('SIGTERM');
|
||||||
|
}
|
||||||
serverProcess = null;
|
serverProcess = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user