NAME
Chandra::Tray - System tray icon with context menu
SYNOPSIS
use Chandra::Tray;
my $tray = Chandra::Tray->new(
app => $app,
icon => '/path/to/icon.png',
tooltip => 'My App',
);
$tray->add_item('Show Window' => sub { $app->show });
$tray->add_separator;
$tray->add_item('Quit' => sub { $app->terminate });
$tray->show;
DESCRIPTION
Creates a native system tray icon with a context menu. Uses NSStatusBar on macOS, GtkStatusIcon on Linux, and Shell_NotifyIcon on Windows.
CONSTRUCTOR
new(%args)
my $tray = Chandra::Tray->new(
app => $app, # Chandra::App instance (required for show)
icon => 'icon.png', # path to icon file
tooltip => 'My App', # hover tooltip
);
METHODS
add_item($label, \&handler)
Add a menu item. Returns $self for chaining.
add_separator()
Add a menu separator. Returns $self.
add_submenu($label, \@items)
Add a submenu. Each item in @items is a hashref with label and handler keys.
set_icon($path)
Change the tray icon. Returns $self.
set_tooltip($text)
Change the tooltip. Returns $self.
update_item($id_or_label, %opts)
Update an existing menu item. Options: label, disabled, checked, handler.
on_click(\&handler)
Set a handler for left-clicking the tray icon.
show()
Display the tray icon. Requires app to be set.
remove()
Remove the tray icon.
is_active()
Returns true if the tray icon is currently displayed.
items()
Returns an arrayref of the current menu items.
item_count()
Returns the number of menu items.