The MenuBar API allows you to create and manage a menu bar icon in the system tray (Windows/Linux) or menu bar (macOS).
Create a new menu bar with the default configuration.
Returns a PendingCreateMenuBar instance for configuring the menu bar before it’s created
use Native\Desktop\Facades\MenuBar;
MenuBar::create()
->icon(storage_path('app/icon.png'))
->label('My App')
->url(route('menubar'))
->width(300)
->height(400);
show()
Show the menu bar window.
hide()
Hide the menu bar window.
label()
Update the menu bar label text.
Label text to display next to the icon
MenuBar::label('5 notifications');
MenuBar::label(''); // Clear label
Set the tooltip text when hovering over the menu bar icon.
MenuBar::tooltip('My Application - Click to open');
icon()
Update the menu bar icon.
MenuBar::icon(storage_path('app/icon-alert.png'));
resize()
Resize the menu bar window.
MenuBar::resize(400, 500);
Set a context menu for the menu bar icon.
Menu object with menu items
use Native\Desktop\Menu\Menu;
use Native\Desktop\Facades\MenuBar;
$menu = Menu::new()
->label('Options')
->submenu(
Menu::new()->label('Settings')->event('settings'),
Menu::new()->label('About')->event('about'),
Menu::new()->separator(),
Menu::new()->label('Quit')->event('quit')
);
MenuBar::contextMenu($menu);
Programmatically show the context menu.
MenuBar::showContextMenu();
These methods are chainable and used when creating a menu bar:
icon()
Set the menu bar icon.
Path to the icon file (PNG recommended)
MenuBar::create()->icon(storage_path('app/menubar-icon.png'));
label()
Set the menu bar label text.
MenuBar::create()->label('App');
Set the tooltip text.
MenuBar::create()->tooltip('My Application');
url()
Set the URL to load in the menu bar window.
MenuBar::create()->url('https://example.com/menubar');
route()
Set the URL using a Laravel route name.
MenuBar::create()->route('menubar.index');
MenuBar::create()->route('user.notifications', ['id' => 1]);
width()
Set the menu bar window width.
MenuBar::create()->width(350);
height()
Set the menu bar window height.
MenuBar::create()->height(450);
resizable()
Set whether the menu bar window can be resized.
Whether window is resizable
MenuBar::create()->resizable(false);
alwaysOnTop()
Set whether the menu bar window stays on top.
Whether window stays on top
MenuBar::create()->alwaysOnTop(true);
showDockIcon()
Set whether to show the dock icon (macOS).
Whether to show dock icon
MenuBar::create()->showDockIcon(false);
showOnAllWorkspaces()
Set whether the menu bar appears on all workspaces.
Whether to show on all workspaces
MenuBar::create()->showOnAllWorkspaces(true);
Only show the context menu, don’t open a window.
Whether to only show context menu
MenuBar::create()->onlyShowContextMenu();
Set a context menu for the menu bar.
Menu object with menu items
use Native\Desktop\Menu\Menu;
$contextMenu = Menu::new()
->label('Context')
->submenu(
Menu::new()->label('Open')->event('open'),
Menu::new()->separator(),
Menu::new()->label('Quit')->event('quit')
);
MenuBar::create()->withContextMenu($contextMenu);
Positioning
position()
Set the position of the menu bar window.
MenuBar::create()->position(100, 100);
windowPosition()
Set the window positioning strategy. Available from the HasPositioner trait.
Position strategy (platform-specific)
MenuBar::create()->windowPosition('trayCenter');
Appearance
backgroundColor()
Set the background color of the menu bar window.
Hex color code (e.g., ‘#FFFFFF’)
MenuBar::create()->backgroundColor('#1a1a1a');
transparent()
Make the menu bar window transparent.
Whether window is transparent
MenuBar::create()->transparent();
vibrancy()
Set the vibrancy effect (macOS).
Vibrancy type: ‘appearance-based’, ‘light’, ‘dark’, ‘under-window’
MenuBar::create()->vibrancy('dark');
lightVibrancy()
Apply light vibrancy effect.
MenuBar::create()->lightVibrancy();
darkVibrancy()
Apply dark vibrancy effect.
MenuBar::create()->darkVibrancy();
blendBackgroundBehindWindow()
Blend the content behind the window.
MenuBar::create()->blendBackgroundBehindWindow();
Advanced Options
webPreferences()
Set Electron web preferences for the menu bar window.
Array of web preference options
MenuBar::create()->webPreferences([
'nodeIntegration' => false,
'contextIsolation' => true,
]);
Complete Examples
use Native\Desktop\Facades\MenuBar;
MenuBar::create()
->icon(storage_path('app/menubar.png'))
->label('Notes')
->tooltip('My Notes App')
->route('menubar.notes')
->width(320)
->height(480)
->resizable(false)
->vibrancy('dark');
use Native\Desktop\Facades\MenuBar;
use Native\Desktop\Menu\Menu;
$contextMenu = Menu::new()
->label('Options')
->submenu(
Menu::new()->label('Dashboard')->event('open-dashboard'),
Menu::new()->label('Settings')->event('open-settings'),
Menu::new()->separator(),
Menu::new()->label('Quit')->event('quit-app')
);
MenuBar::create()
->icon(storage_path('app/tray-icon.png'))
->tooltip('My Application')
->onlyShowContextMenu()
->withContextMenu($contextMenu);
use Native\Desktop\Facades\MenuBar;
// Create initial menu bar
MenuBar::create()
->icon(storage_path('app/icon-idle.png'))
->label('')
->route('menubar');
// Later, update the icon and label based on notifications
$notificationCount = 5;
if ($notificationCount > 0) {
MenuBar::icon(storage_path('app/icon-alert.png'));
MenuBar::label((string) $notificationCount);
MenuBar::tooltip("{$notificationCount} new notifications");
} else {
MenuBar::icon(storage_path('app/icon-idle.png'));
MenuBar::label('');
MenuBar::tooltip('No new notifications');
}
use Native\Desktop\Facades\MenuBar;
MenuBar::create()
->icon(storage_path('app/menubar.png'))
->route('menubar')
->width(300)
->height(400)
->windowPosition('trayCenter')
->showOnAllWorkspaces()
->vibrancy('appearance-based');