Ende.Tray

interface · desktop apps only

interface Ende.Tray extends TrayEventHandlers

class · desktop apps only

class Ende.Tray extends EventTarget implements Disposable

A persistent icon in the OS status area (macOS menu bar extras, Windows system tray, Linux AppIndicator).

The icon is removed from the OS when Tray.destroy is called. Multiple trays may be created.

Constructors

constructor

new Tray()

Properties

trayId

readonly trayId: number

Methods

setIcon

setIcon(pngBytes: Uint8Array): void

Set the tray icon image from PNG-encoded bytes.

setIconDark

setIconDark(pngBytes: Uint8Array | null): void

Set the tray icon used in OS dark mode. Pass null to clear it.

setTooltip

setTooltip(text: string | null): void

Set the tooltip shown on hover. Pass null or an empty string to clear the tooltip.

setMenu

setMenu(menu: MenuItem[] | null): void

Set the right-click context menu. Click events are delivered as "menuclick" events on the tray. Pass null to remove any menu previously set.

getBounds

getBounds(): TrayBounds | null

The tray icon's bounding rectangle in screen coordinates, or null if the icon has no on-screen position yet or the platform can't report it. Typically called from a "click" handler to position a popover BrowserWindow (created with frameless + noActivate) under the icon.

attachPanel

attachPanel(options: TrayPanelOptions | string): TrayPanel

Attach a frameless, non-activating popover window to this tray icon (the classic menu-bar-app pattern). The returned panel toggles on tray click, is positioned under the icon via Tray.getBounds, and hides when it loses focus.

Convenience built on the primitives; for full control create a frameless + noActivate BrowserWindow yourself.

const tray = new Ende.Tray();
tray.setIcon(iconBytes);
const panel = tray.attachPanel({ url: "https://localhost:8000/panel" });
panel.window.bind("doThing", async () => { ... });

Pass a string as shorthand for { url }. On Linux the icon position can't be queried, so the panel shows at its last position rather than anchored to the icon.

destroy

destroy(): void

Remove the tray icon from the OS status area. The instance must not be used after this call.

[Symbol.dispose]

[Symbol.dispose](): void

addEventListener

addEventListener<K extends keyof TrayEventMap>(type: K, listener: (this: Tray, ev: TrayEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void

removeEventListener

removeEventListener<K extends keyof TrayEventMap>(type: K, listener: (this: Tray, ev: TrayEventMap[K]) => any, options?: boolean | EventListenerOptions): void
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void