Fix desktop terminal link and context menu behavior

This commit is contained in:
Mohamed Boudra
2026-03-28 11:14:43 +07:00
parent 7ca428677c
commit a3aed9b8b6
5 changed files with 73 additions and 2 deletions

View File

@@ -1,4 +1,9 @@
import { app, Menu, BrowserWindow } from "electron";
import { app, Menu, BrowserWindow, ipcMain } from "electron";
type ShowContextMenuInput = {
kind?: "terminal";
hasSelection?: boolean;
};
function withBrowserWindow(
callback: (win: BrowserWindow) => void,
@@ -89,4 +94,36 @@ export function setupApplicationMenu(): void {
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
ipcMain.handle("paseo:menu:showContextMenu", (event, input?: ShowContextMenuInput) => {
const win = BrowserWindow.fromWebContents(event.sender);
if (!win) {
return;
}
if (input?.kind !== "terminal") {
return;
}
const menu = Menu.buildFromTemplate([
{
label: "Copy",
role: "copy",
enabled: input.hasSelection === true,
},
{
label: "Paste",
role: "paste",
},
{
type: "separator",
},
{
label: "Select All",
role: "selectAll",
},
]);
menu.popup({ window: win });
});
}