You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wire deterministic context-menu close signaling across Electron and renderer (#2932)
Context-menu opens previously produced renderer callbacks only on
selection (0 or 1 events). This change makes the lifecycle
deterministic: every menu open now emits exactly one completion signal,
with `null` on cancel and item id on selection.
- **Main process: single terminal callback per popup**
- Updated `emain/emain-menu.ts` to use `menu.popup({ callback })`.
- Tracks whether a menu item click occurred during the popup.
- Emits `contextmenu-click: null` only when the menu closes without
selection.
- Suppresses duplicate close events when a click already fired.
- **Preload + API typing: nullable context-menu callback payload**
- Updated preload bridge and `frontend/types/custom.d.ts` so:
- `onContextMenuClick` now accepts `(id: string | null) => void`.
- Keeps existing channel semantics while allowing explicit cancel
signal.
- **Renderer context menu model: close/select/cancel hooks**
- Extended `showContextMenu` with optional `opts`:
- `onSelect?: (item) => void`
- `onCancel?: () => void`
- `onClose?: (item: MenuItem | null) => void`
- Execution order on selection:
1. original item `click`
2. `onSelect`
3. `onClose`
- Execution order on cancel:
1. `onCancel`
2. `onClose(null)`
- **Targeted behavior tests**
- Expanded `frontend/app/store/contextmenu.test.ts` to verify:
- singleton wiring still initializes once,
- selection path ordering (`click -> onSelect -> onClose`),
- cancel path ordering (`onCancel -> onClose(null)`).
```ts
ContextMenuModel.getInstance().showContextMenu(menu, e, {
onSelect: (item) => { /* after item.click */ },
onCancel: () => { /* close without selection */ },
onClose: (itemOrNull) => { /* always called */ },
});
```
<screenshot>
Not applicable — this is a behavioral/API flow change in native context
menu lifecycle rather than a visual UI update.
</screenshot>
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: sawka <[email protected]>
Co-authored-by: sawka <[email protected]>
0 commit comments