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

FieldTypeDefault
icon_path[]const u8""
tooltip[]const u8""
items[]const TrayMenuItem&.

TrayMenuItem

FieldTypeDefault
idTrayItemId (u32)0
label[]const u8""
separatorboolfalse
enabledbooltrue

PlatformServices methods

  • createTray(options) -- create or replace the tray icon
  • updateTrayMenu(items) -- update menu items without recreating the tray
  • removeTray() -- 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 => {},
    }
}