@mytec: iter2.4 ready for testing
This commit is contained in:
@@ -270,11 +270,11 @@ function createMainWindow() {
|
||||
|
||||
// Save window state on close and trigger shutdown
|
||||
mainWindow.on('close', () => {
|
||||
log('[CLOSE] Window close event fired, isQuitting=' + isQuitting);
|
||||
try {
|
||||
const bounds = mainWindow.getBounds();
|
||||
store.set('windowState', bounds);
|
||||
} catch (_e) {}
|
||||
log('Main window closing — killing backend');
|
||||
isQuitting = true;
|
||||
killBackend();
|
||||
});
|
||||
@@ -321,34 +321,43 @@ function createMainWindow() {
|
||||
|
||||
function killBackend() {
|
||||
const pid = backendPid || backendProcess?.pid;
|
||||
if (!pid) return;
|
||||
if (!pid) {
|
||||
log('[KILL] killBackend() called — no backend PID to kill');
|
||||
return;
|
||||
}
|
||||
|
||||
log(`Killing backend (PID ${pid})...`);
|
||||
log(`[KILL] killBackend() called, platform=${process.platform}, PID=${pid}`);
|
||||
|
||||
try {
|
||||
if (process.platform === 'win32') {
|
||||
// Windows: taskkill with /F (force) /T (tree — kills child processes too)
|
||||
log(`[KILL] Running: taskkill /F /T /PID ${pid}`);
|
||||
execSync(`taskkill /F /T /PID ${pid}`, { stdio: 'ignore' });
|
||||
log('[KILL] taskkill completed successfully');
|
||||
} else {
|
||||
// Unix: kill process group
|
||||
try {
|
||||
log(`[KILL] Sending SIGTERM to process group -${pid}`);
|
||||
process.kill(-pid, 'SIGTERM');
|
||||
} catch (_e) {
|
||||
log(`[KILL] Process group kill failed, sending SIGTERM to PID ${pid}`);
|
||||
process.kill(pid, 'SIGTERM');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log(`[KILL] Primary kill failed: ${e.message}, trying SIGKILL fallback`);
|
||||
// Fallback: try normal kill via process handle
|
||||
try {
|
||||
backendProcess?.kill('SIGKILL');
|
||||
log('[KILL] Fallback SIGKILL sent via process handle');
|
||||
} catch (_e2) {
|
||||
// Already dead — that's fine
|
||||
log('[KILL] Fallback also failed — process likely already dead');
|
||||
}
|
||||
}
|
||||
|
||||
backendPid = null;
|
||||
backendProcess = null;
|
||||
log('Backend killed');
|
||||
log(`[KILL] Backend cleanup complete (PID was ${pid})`);
|
||||
}
|
||||
|
||||
// ── App lifecycle ──────────────────────────────────────────────────
|
||||
@@ -381,7 +390,7 @@ app.whenReady().then(async () => {
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
log('Event: window-all-closed');
|
||||
log('[CLOSE] window-all-closed fired');
|
||||
isQuitting = true;
|
||||
killBackend();
|
||||
|
||||
@@ -397,13 +406,13 @@ app.on('activate', () => {
|
||||
});
|
||||
|
||||
app.on('before-quit', () => {
|
||||
log('Event: before-quit');
|
||||
log('[CLOSE] before-quit fired');
|
||||
isQuitting = true;
|
||||
killBackend();
|
||||
});
|
||||
|
||||
app.on('will-quit', () => {
|
||||
log('Event: will-quit');
|
||||
log('[CLOSE] will-quit fired');
|
||||
killBackend();
|
||||
|
||||
if (backendLogStream) {
|
||||
@@ -414,6 +423,10 @@ app.on('will-quit', () => {
|
||||
|
||||
// Last resort: ensure backend is killed when Node process exits
|
||||
process.on('exit', () => {
|
||||
try {
|
||||
console.log(`[KILL] process.exit handler, backendPid=${backendPid}`);
|
||||
} catch (_e) { /* log stream may be closed */ }
|
||||
|
||||
if (backendPid) {
|
||||
try {
|
||||
if (process.platform === 'win32') {
|
||||
|
||||
Reference in New Issue
Block a user