fix two clawx instances bug (#294)

This commit is contained in:
paisley
2026-03-04 21:20:21 +08:00
committed by GitHub
Unverified
parent fd58e721bd
commit 5ddb7d281d
2 changed files with 52 additions and 13 deletions

View File

@@ -37,6 +37,15 @@ import { ensureBuiltinSkillsInstalled } from '../utils/skill-config';
// set `"disable-hardware-acceleration": false` in the app config (future).
app.disableHardwareAcceleration();
// Prevent multiple instances of the app from running simultaneously.
// Without this, two instances each spawn their own gateway process on the
// same port, then each treats the other's gateway as "orphaned" and kills
// it — creating an infinite kill/restart loop on Windows.
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
}
// Global references
let mainWindow: BrowserWindow | null = null;
const gatewayManager = new GatewayManager();
@@ -242,6 +251,15 @@ async function initialize(): Promise<void> {
});
}
// When a second instance is launched, focus the existing window instead.
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();
}
});
// Application lifecycle
app.whenReady().then(() => {
initialize();