Problem
When using statusItem(), there is no way to attach a native context menu to the status bar icon. Right-clicking (or ctrl-clicking) does nothing.
For agent-driven UIs (e.g. companion panels, monitoring tools), a right-click menu is essential for actions like Quit, Toggle visibility, Open inspector, etc. Without it, users must build these controls inside the popover HTML, which is cumbersome and non-native.
Proposed Solution
Add native NSMenu support for status items:
Swift side:
- Handle
rightMouseUp and ctrl+leftMouseUp on the status item button
- Parse a new
status-menu JSON command to build NSMenu items dynamically
- Emit
{"type":"menu","id":"..."} on stdout when a menu item is selected
Node wrapper:
- Add
setMenu(items) method on the GlimpseWindow instance
- Emit
'menu' event with the selected item id
Usage
const menu = statusItem(html, { title: 'My Agent' });
menu.setMenu([
{ id: 'inspect', title: 'Open Inspector' },
{ id: 'quit', title: 'Quit' },
]);
menu.on('menu', (id) => {
if (id === 'quit') process.exit(0);
});
I have a working implementation and will open a PR shortly.
Problem
When using
statusItem(), there is no way to attach a native context menu to the status bar icon. Right-clicking (or ctrl-clicking) does nothing.For agent-driven UIs (e.g. companion panels, monitoring tools), a right-click menu is essential for actions like Quit, Toggle visibility, Open inspector, etc. Without it, users must build these controls inside the popover HTML, which is cumbersome and non-native.
Proposed Solution
Add native
NSMenusupport for status items:Swift side:
rightMouseUpandctrl+leftMouseUpon the status item buttonstatus-menuJSON command to buildNSMenuitems dynamically{"type":"menu","id":"..."}on stdout when a menu item is selectedNode wrapper:
setMenu(items)method on theGlimpseWindowinstance'menu'event with the selected item idUsage
I have a working implementation and will open a PR shortly.