Skip to main content

MenuBar API

The MenuBar API allows you to create and manage a menu bar icon in the system tray (Windows/Linux) or menu bar (macOS).

Creating a MenuBar

Native\Desktop\Facades\MenuBar::create()

Create a new menu bar with the default configuration.
PendingCreateMenuBar
object
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.
MenuBar::show();

hide()

Hide the menu bar window.
MenuBar::hide();

label()

Update the menu bar label text.
label
string
required
Label text to display next to the icon
MenuBar::label('5 notifications');
MenuBar::label(''); // Clear label

tooltip()

Set the tooltip text when hovering over the menu bar icon.
tooltip
string
required
Tooltip text
MenuBar::tooltip('My Application - Click to open');

icon()

Update the menu bar icon.
icon
string
required
Path to the icon file
MenuBar::icon(storage_path('app/icon-alert.png'));

resize()

Resize the menu bar window.
width
int
required
New width in pixels
height
int
required
New height in pixels
MenuBar::resize(400, 500);

contextMenu()

Set a context menu for the menu bar icon.
contextMenu
Menu
required
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);

showContextMenu()

Programmatically show the context menu.
MenuBar::showContextMenu();
These methods are chainable and used when creating a menu bar:

icon()

Set the menu bar icon.
icon
string
required
Path to the icon file (PNG recommended)
MenuBar::create()->icon(storage_path('app/menubar-icon.png'));

label()

Set the menu bar label text.
label
string
default:"''"
Label text to display
MenuBar::create()->label('App');

tooltip()

Set the tooltip text.
tooltip
string
default:"''"
Tooltip text
MenuBar::create()->tooltip('My Application');

url()

Set the URL to load in the menu bar window.
url
string
required
Full URL to load
MenuBar::create()->url('https://example.com/menubar');

route()

Set the URL using a Laravel route name.
route
string
required
Laravel route name
parameters
array
default:"[]"
Route parameters
MenuBar::create()->route('menubar.index');
MenuBar::create()->route('user.notifications', ['id' => 1]);

width()

Set the menu bar window width.
width
int
required
Width in pixels
MenuBar::create()->width(350);

height()

Set the menu bar window height.
height
int
required
Height in pixels
MenuBar::create()->height(450);

resizable()

Set whether the menu bar window can be resized.
resizable
bool
default:"true"
Whether window is resizable
MenuBar::create()->resizable(false);

alwaysOnTop()

Set whether the menu bar window stays on top.
alwaysOnTop
bool
default:"true"
Whether window stays on top
MenuBar::create()->alwaysOnTop(true);

showDockIcon()

Set whether to show the dock icon (macOS).
show
bool
default:"true"
Whether to show dock icon
MenuBar::create()->showDockIcon(false);

showOnAllWorkspaces()

Set whether the menu bar appears on all workspaces.
show
bool
default:"true"
Whether to show on all workspaces
MenuBar::create()->showOnAllWorkspaces(true);

onlyShowContextMenu()

Only show the context menu, don’t open a window.
onlyContextMenu
bool
default:"true"
Whether to only show context menu
MenuBar::create()->onlyShowContextMenu();

withContextMenu()

Set a context menu for the menu bar.
menu
Menu
required
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.
x
int
required
X coordinate in pixels
y
int
required
Y coordinate in pixels
MenuBar::create()->position(100, 100);

windowPosition()

Set the window positioning strategy. Available from the HasPositioner trait.
position
string
required
Position strategy (platform-specific)
MenuBar::create()->windowPosition('trayCenter');

Appearance

backgroundColor()

Set the background color of the menu bar window.
color
string
required
Hex color code (e.g., ‘#FFFFFF’)
MenuBar::create()->backgroundColor('#1a1a1a');

transparent()

Make the menu bar window transparent.
transparent
bool
default:"true"
Whether window is transparent
MenuBar::create()->transparent();

vibrancy()

Set the vibrancy effect (macOS).
vibrancy
string
required
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.
preferences
array
required
Array of web preference options
MenuBar::create()->webPreferences([
    'nodeIntegration' => false,
    'contextIsolation' => true,
]);

Complete Examples

Basic Menu Bar

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');

Context Menu Only

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);

Dynamic Menu Bar Updates

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');

Build docs developers (and LLMs) love