System Tray
zero-native supports system tray icons with menus. Tray actions dispatch as CommandEvent with name "tray.action" in the runtime.
Tray support is currently implemented on macOS. Linux returns UnsupportedService until a portable status notifier implementation is selected.
TrayOptions
| Field | Type | Default |
|---|---|---|
icon_path | []const u8 | "" |
tooltip | []const u8 | "" |
items | []const TrayMenuItem | &. |
TrayMenuItem
| Field | Type | Default |
|---|---|---|
id | TrayItemId (u32) | 0 |
label | []const u8 | "" |
separator | bool | false |
enabled | bool | true |
PlatformServices methods
createTray(options)-- create or replace the tray iconupdateTrayMenu(items)-- update menu items without recreating the trayremoveTray()-- remove the tray icon
Handling tray actions
When a user clicks a tray menu item, the runtime dispatches a CommandEvent with the name "tray.action". Use your event_fn to handle it:
fn event(context: *anyopaque, runtime: *Runtime, ev: Event) anyerror!void {
switch (ev) {
.command => |cmd| {
if (std.mem.eql(u8, cmd.name, "tray.action")) {
// Handle tray menu click
}
},
else => {},
}
}