Summary
Please expose customizable tray icon clicks separately from menu-item actions, and make automatic menu presentation configurable.
A common Windows tray-app flow is:
- Left-click the icon: restore and activate the existing main window.
- Right-click the icon: show the tray menu.
- Select Exit: quit the application.
With Electrobun 2.0.2, calling Tray.setMenu() makes both left- and right-click open the menu. There is no public option to disable menu-on-left-click while retaining the right-click menu, and the current click payload does not identify the mouse button.
Environment
- Electrobun 2.0.2
- Windows x64
- Bun main process, native WebView2 renderer
Minimal reproduction
Supply an ICO at the bundled path below:
import { BrowserWindow, Tray, Utils } from "electrobun/main";
const win = new BrowserWindow({ html: "<h1>Tray reproduction</h1>" });
const tray = new Tray({
title: "Tray reproduction",
image: "views://mainview/icon.ico",
template: false,
});
tray.setMenu([
{ type: "normal", label: "Show window", action: "show" },
{ type: "normal", label: "Exit", action: "quit" },
]);
tray.on("tray-clicked", (event: unknown) => {
const { action } = (event as { data: { action: string } }).data;
console.log("tray-clicked", action);
if (action === "" || action === "show") {
if (win.isMinimized()) win.unminimize();
win.show();
win.activate();
}
if (action === "quit") Utils.quit();
});
win.hide();Left-click the tray icon after the menu has been installed. The menu opens instead of emitting an icon-activation event that can restore the window. Right-click also opens the menu.
Source evidence
In TrayWindowProc at v2.0.2, WM_LBUTTONUP falls through directly into WM_RBUTTONUP; the shared branch invokes TrackPopupMenu when a context menu exists. The empty-action callback is reached only when no menu exists.
The tray event payload has id, action, and optional data, but no mouse-button information.
Requested API
The exact API names are up to the maintainers. For example, a new option such as menuOnLeftClick: false, plus an icon-click event with button: "left" | "right", would let applications implement this directly:
// Proposed API only; these options/events do not currently exist.
const tray = new Tray({ image: "...", menuOnLeftClick: false });
tray.setMenu(menu);
tray.on("click", (event) => {
if (event.button === "left") {
win.show();
win.activate();
}
});
// Right-click continues to show the installed native menu.Please keep menu-item action events separate from raw icon activation, preserve existing defaults for compatibility, and document platform capabilities. Linux AppIndicator limitations can remain explicit rather than requiring identical behavior everywhere.
Why this matters
This small interaction currently requires an application-level platform workaround. In our Windows app, we had to use a separate WinForms NotifyIcon helper process to obtain independent left-click activation and right-click menus. A public Electrobun API would eliminate that extra process and its lifecycle/IPC maintenance.
Acceptance criteria
- Installing a tray menu does not prevent opt-in custom left-click activation.
- Left-click can restore a window without opening the menu.
- Right-click can retain the native tray menu.
- Raw icon events identify the mouse button.
- Menu-item actions and normal tray cleanup continue to work.
Activity
0No activity yet.