Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(desktop): suppress Electron 43 system context menu on Linux (#511)
landf031a4d29d8
diff --git a/apps/desktop/electron/main/bootstrap/launcher.ts b/apps/desktop/electron/main/bootstrap/launcher.tsindex 1c561f074..b2b423f0c 100644--- a/apps/desktop/electron/main/bootstrap/launcher.ts+++ b/apps/desktop/electron/main/bootstrap/launcher.ts@@ -12,6 +12,7 @@ import {import type { HostProcess } from "../host-process";import type { Logger } from "../logger";import type { WindowLifecycleState } from "./window";+import { suppressLinuxFramelessSystemMenu } from "../frameless-system-menu";export type LauncherState = {creationPromise: Promise<BrowserWindow> | null;@@ -103,6 +104,7 @@ export function createLauncher({},});state.pluginLauncherWindow = window;+ suppressLinuxFramelessSystemMenu(window);if (process.platform === "darwin") {// Join every Space and float above this app's own fullscreen window, butdiff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.tsindex a9c3e78e9..046d50c25 100644--- a/apps/desktop/electron/main/bootstrap/window.ts+++ b/apps/desktop/electron/main/bootstrap/window.ts@@ -33,6 +33,7 @@ import {type WorkPanelReservationState,} from "../work-panel-window";import { readWindowState, writeWindowState } from "../window-preferences";+import { suppressLinuxFramelessSystemMenu } from "../frameless-system-menu";function windowsIconPath(): string | undefined {if (process.platform !== "win32") return undefined;@@ -198,6 +199,7 @@ export async function createWindow({},});const window = windowState.mainWindow;+ suppressLinuxFramelessSystemMenu(window);const initialBounds = window.getBounds();windowState.workPanelBaseBounds = savedState ? { ...savedState } : { ...initialBounds };windowState.workPanelLastAppliedBounds = { ...initialBounds };diff --git a/apps/desktop/electron/main/frameless-system-menu.ts b/apps/desktop/electron/main/frameless-system-menu.tsnew file mode 100644index 000000000..33e31d6d1--- /dev/null+++ b/apps/desktop/electron/main/frameless-system-menu.ts@@ -0,0 +1,22 @@+import type { BrowserWindow } from "electron";++// Electron 43 introduced the `system-context-menu` event, which fires when the+// user right-clicks any `-webkit-app-region: drag` region inside a frameless+// window (win32 + linux). The frameless titlebar's 46 px drag strip is exactly+// such a region.+//+// On Linux/X11 the resulting native GTK menu takes an active pointer grab.+// Dismissing it with a mouse click leaks the grab, and the whole desktop stops+// receiving pointer events until the session is restarted (see issue #511).+// The frameless shell owns its own titlebar controls in the renderer, so this+// native menu adds nothing and its absence returns behavior to the Electron 42+// baseline.+//+// Windows keeps the standard system menu — the crash is X11-specific and the+// menu is the expected win32 chrome for a frameless titlebar.+export function suppressLinuxFramelessSystemMenu(window: BrowserWindow): void {+ if (process.platform !== "linux") return;+ window.on("system-context-menu", (event) => {+ event.preventDefault();+ });+}diff --git a/apps/desktop/electron/main/plugin-panel-host.ts b/apps/desktop/electron/main/plugin-panel-host.tsindex 544bbcc0d..84a65850f 100644--- a/apps/desktop/electron/main/plugin-panel-host.ts+++ b/apps/desktop/electron/main/plugin-panel-host.ts@@ -4,6 +4,7 @@ import { join, resolve } from "node:path";import { catalogs, resolveLocale } from "@pi-desktop/i18n";import { isNetUrlAllowed, THEME_ASSET_SCHEME } from "@pi-desktop/plugin-sdk";import { builtinWindowBackground } from "@pi-desktop/shared";+import { suppressLinuxFramelessSystemMenu } from "./frameless-system-menu";import {isPluginPanelWindowControlAction,PLUGIN_PANEL_MIN_SIZE,@@ -468,6 +469,7 @@ export class PluginPanelHost {// A panel owns its visible surface; do not add a native application menu// to the window around the plugin's own UI.win.setMenu(null);+ suppressLinuxFramelessSystemMenu(win);// A panel gets exactly one web contents. `window.open` would otherwise mint// a chromeless window outside the egress policy applied above.