diff --git a/ui-electrobun/src/bun/index.ts b/ui-electrobun/src/bun/index.ts index 1bd55df..bf7da04 100644 --- a/ui-electrobun/src/bun/index.ts +++ b/ui-electrobun/src/bun/index.ts @@ -5,7 +5,7 @@ * Fix #2: Path traversal guard on files.list/read/write via path-guard.ts. */ -import { BrowserWindow, BrowserView, Updater } from "electrobun/bun"; +import { BrowserWindow, BrowserView, Updater, Electrobun } from "electrobun/bun"; import { PtyClient } from "./pty-client.ts"; import { settingsDb } from "./settings-db.ts"; import { sessionDb } from "./session-db.ts"; @@ -192,4 +192,25 @@ mainWindow = new BrowserWindow({ }, }); +// Prevent GTK's false Ctrl+click detection from closing the window on initial load. +// WebKitGTK reports stale modifier state (0x14 = Ctrl+Alt) after SIGTERM of previous instance, +// which Electrobun interprets as a Cmd+click → "open in new window" → closes the main window. +// Fix: intercept new-window-open globally and suppress it. +try { + // @ts-ignore — electrobunEventEmitter is an internal export + const mod = await import("electrobun/bun"); + const emitter = (mod as any).electrobunEventEmitter ?? (mod as any).default?.electrobunEventEmitter; + if (emitter?.on) { + emitter.on("new-window-open", (event: any) => { + console.log(`[new-window-open] Blocked false Ctrl+click: ${JSON.stringify(event?.detail ?? event)}`); + if (event?.preventDefault) event.preventDefault(); + }); + console.log("[new-window-open] Handler registered successfully"); + } else { + console.warn("[new-window-open] Could not find event emitter in electrobun/bun exports"); + } +} catch (err) { + console.warn("[new-window-open] Could not register handler:", err); +} + console.log("Agent Orchestrator (Electrobun) started!");