TypeScript/JavaScript API bindings for Tauri applications providing comprehensive desktop app functionality
—
Native desktop integration features including application lifecycle management, system tray icons, context menus, and platform-specific functionality for seamless desktop experience.
Core application information and lifecycle management.
/**
* Get application version from config
* @returns Application version string
*/
function getVersion(): Promise<string>;
/**
* Get application name from config
* @returns Application name string
*/
function getName(): Promise<string>;
/**
* Get Tauri framework version
* @returns Tauri version string
*/
function getTauriVersion(): Promise<string>;
/**
* Get application identifier from config
* @returns Application identifier string
*/
function getIdentifier(): Promise<string>;
/**
* Show application in dock/taskbar (macOS specific)
*/
function show(): Promise<void>;
/**
* Hide application from dock/taskbar (macOS specific)
*/
function hide(): Promise<void>;
/**
* Get the default window icon
* @returns Default icon or null if not set
*/
function defaultWindowIcon(): Promise<Image | null>;
/**
* Set application theme
* @param theme - Theme to apply ('light', 'dark', 'auto', or null for system)
*/
function setTheme(theme?: Theme | null): Promise<void>;
/**
* Set dock visibility (macOS specific)
* @param visible - Whether dock should be visible
*/
function setDockVisibility(visible: boolean): Promise<void>;
/**
* Get the installation bundle type
* @returns Bundle type used for this installation
*/
function getBundleType(): Promise<BundleType>;
type Theme = 'light' | 'dark' | 'auto';
enum BundleType {
Nsis = 'nsis',
Msi = 'msi',
Deb = 'deb',
Rpm = 'rpm',
AppImage = 'appImage',
App = 'app'
}System tray icon management with support for icons, menus, and event handling.
/**
* System tray icon management
*/
class TrayIcon {
/**
* Create a new system tray icon
* @param options - Tray icon configuration
* @returns Promise resolving to TrayIcon instance
*/
static new(options: TrayIconOptions): Promise<TrayIcon>;
/**
* Get tray icon by ID
* @param id - Tray icon identifier
* @returns TrayIcon instance or null if not found
*/
static getById(id: string): Promise<TrayIcon | null>;
/**
* Remove tray icon by ID
* @param id - Tray icon identifier
* @returns true if removed successfully
*/
static removeById(id: string): Promise<boolean>;
/**
* Set the tray icon image
* @param icon - Icon image, path, or null to remove
*/
setIcon(icon: Image | string | null): Promise<void>;
/**
* Set the tray icon context menu
* @param menu - Menu to show on right-click, or null to remove
*/
setMenu(menu: Menu | null): Promise<void>;
/**
* Set the tray icon tooltip text
* @param tooltip - Tooltip text or null to remove
*/
setTooltip(tooltip: string | null): Promise<void>;
/**
* Set the tray icon title (macOS only)
* @param title - Title text or null to remove
*/
setTitle(title: string | null): Promise<void>;
/**
* Set tray icon visibility
* @param visible - Whether the icon should be visible
*/
setVisible(visible: boolean): Promise<void>;
/**
* Set temporary directory path for tray icon assets
* @param path - Directory path or null to use default
*/
setTempDirPath(path: string | null): Promise<void>;
/**
* Set whether icon should be treated as template (macOS only)
* @param asTemplate - Whether to use template rendering
*/
setIconAsTemplate(asTemplate: boolean): Promise<void>;
/**
* Set whether menu shows on left click instead of right click
* @param onLeft - Whether to show menu on left click
*/
setMenuOnLeftClick(onLeft: boolean): Promise<void>;
}
interface TrayIconOptions {
/** Unique identifier for the tray icon */
id?: string;
/** Icon image or path */
icon?: Image | string;
/** Context menu */
menu?: Menu;
/** Tooltip text */
tooltip?: string;
/** Title text (macOS only) */
title?: string;
/** Menu position preference */
menuOnLeftClick?: boolean;
/** Icon template mode (macOS only) */
iconAsTemplate?: boolean;
/** Temporary directory for assets */
tempDirPath?: string;
}Handle tray icon interactions and events.
/**
* Tray icon event types
*/
type TrayIconEvent =
| { type: 'Click'; position: PhysicalPosition; size: PhysicalSize; button: MouseButton; buttonState: MouseButtonState }
| { type: 'DoubleClick'; position: PhysicalPosition; size: PhysicalSize; button: MouseButton; buttonState: MouseButtonState }
| { type: 'Enter'; position: PhysicalPosition; size: PhysicalSize }
| { type: 'Move'; position: PhysicalPosition; size: PhysicalSize }
| { type: 'Leave'; position: PhysicalPosition; size: PhysicalSize };
type MouseButton = 'Left' | 'Right' | 'Middle';
type MouseButtonState = 'Up' | 'Down';Comprehensive menu system for application menus, context menus, and tray menus.
/**
* Menu container for organizing menu items
*/
class Menu {
/**
* Create a new empty menu
* @returns Promise resolving to Menu instance
*/
static new(): Promise<Menu>;
/**
* Append items to the menu
* @param items - Menu item or array of menu items to append
*/
append(items: MenuItem | MenuItem[]): Promise<void>;
/**
* Prepend items to the menu
* @param items - Menu item or array of menu items to prepend
*/
prepend(items: MenuItem | MenuItem[]): Promise<void>;
/**
* Insert items at specific position
* @param items - Menu item or array of menu items to insert
* @param position - Index position to insert at
*/
insert(items: MenuItem | MenuItem[], position: number): Promise<void>;
/**
* Remove item at specific position
* @param position - Index of item to remove
*/
remove(position: number): Promise<void>;
/**
* Remove all items from the menu
*/
removeAll(): Promise<void>;
/**
* Get all items in the menu
* @returns Array of menu items
*/
items(): Promise<MenuItem[]>;
/**
* Get item at specific position
* @param position - Index of item to get
* @returns Menu item or null if not found
*/
get(position: number): Promise<MenuItem | null>;
/**
* Show menu as popup at specified position
* @param position - Position to show popup, or null for cursor position
*/
popup(position?: Position): Promise<void>;
/**
* Set this menu as the application menu (macOS/Linux)
*/
setAsAppMenu(): Promise<void>;
/**
* Set this menu as the window menu (Windows)
*/
setAsWindowMenu(): Promise<void>;
}Various types of menu items with different behaviors and properties.
/**
* Base menu item interface
*/
interface MenuItemBase {
text(): Promise<string>;
setText(text: string): Promise<void>;
isEnabled(): Promise<boolean>;
setEnabled(enabled: boolean): Promise<void>;
setAccelerator(accelerator: string | null): Promise<void>;
}
/**
* Regular clickable menu item
*/
class MenuItem implements MenuItemBase {
/**
* Create a new menu item
* @param text - Display text
* @param enabled - Whether item is enabled
* @param accelerator - Keyboard shortcut (e.g., "Ctrl+N")
*/
constructor(text: string, enabled?: boolean, accelerator?: string);
text(): Promise<string>;
setText(text: string): Promise<void>;
isEnabled(): Promise<boolean>;
setEnabled(enabled: boolean): Promise<void>;
setAccelerator(accelerator: string | null): Promise<void>;
}
/**
* Checkable menu item with toggle state
*/
class CheckMenuItem implements MenuItemBase {
/**
* Create a new check menu item
* @param text - Display text
* @param enabled - Whether item is enabled
* @param checked - Initial checked state
* @param accelerator - Keyboard shortcut
*/
constructor(text: string, enabled?: boolean, checked?: boolean, accelerator?: string);
text(): Promise<string>;
setText(text: string): Promise<void>;
isEnabled(): Promise<boolean>;
setEnabled(enabled: boolean): Promise<void>;
setAccelerator(accelerator: string | null): Promise<void>;
/**
* Get checked state
* @returns true if checked
*/
isChecked(): Promise<boolean>;
/**
* Set checked state
* @param checked - Whether item should be checked
*/
setChecked(checked: boolean): Promise<void>;
}
/**
* Menu item with icon
*/
class IconMenuItem implements MenuItemBase {
/**
* Create a new icon menu item
* @param text - Display text
* @param enabled - Whether item is enabled
* @param accelerator - Keyboard shortcut
* @param icon - Menu icon
*/
constructor(text: string, enabled?: boolean, accelerator?: string, icon?: MenuIcon);
text(): Promise<string>;
setText(text: string): Promise<void>;
isEnabled(): Promise<boolean>;
setEnabled(enabled: boolean): Promise<void>;
setAccelerator(accelerator: string | null): Promise<void>;
/**
* Set the menu item icon
* @param icon - Icon to set or null to remove
*/
setIcon(icon: MenuIcon | null): Promise<void>;
}
/**
* Submenu container
*/
class Submenu implements MenuItemBase {
/**
* Create a new submenu
* @param text - Display text
* @param enabled - Whether submenu is enabled
*/
constructor(text: string, enabled?: boolean);
text(): Promise<string>;
setText(text: string): Promise<void>;
isEnabled(): Promise<boolean>;
setEnabled(enabled: boolean): Promise<void>;
setAccelerator(accelerator: string | null): Promise<void>;
/**
* Append items to the submenu
* @param items - Menu item or array of items to append
*/
append(items: MenuItem | MenuItem[]): Promise<void>;
/**
* Prepend items to the submenu
* @param items - Menu item or array of items to prepend
*/
prepend(items: MenuItem | MenuItem[]): Promise<void>;
/**
* Insert items at specific position
* @param items - Menu item or array of items to insert
* @param position - Index position to insert at
*/
insert(items: MenuItem | MenuItem[], position: number): Promise<void>;
/**
* Remove item at specific position
* @param position - Index of item to remove
*/
remove(position: number): Promise<void>;
/**
* Get all items in the submenu
* @returns Array of menu items
*/
items(): Promise<MenuItem[]>;
}
/**
* Platform-specific predefined menu items
*/
class PredefinedMenuItem {
/**
* Menu separator
*/
static separator(): PredefinedMenuItem;
/**
* Copy menu item (Ctrl+C/Cmd+C)
*/
static copy(): PredefinedMenuItem;
/**
* Cut menu item (Ctrl+X/Cmd+X)
*/
static cut(): PredefinedMenuItem;
/**
* Paste menu item (Ctrl+V/Cmd+V)
*/
static paste(): PredefinedMenuItem;
/**
* Select All menu item (Ctrl+A/Cmd+A)
*/
static selectAll(): PredefinedMenuItem;
/**
* Undo menu item (Ctrl+Z/Cmd+Z)
*/
static undo(): PredefinedMenuItem;
/**
* Redo menu item (Ctrl+Y/Cmd+Shift+Z)
*/
static redo(): PredefinedMenuItem;
/**
* Minimize window menu item
*/
static minimize(): PredefinedMenuItem;
/**
* Hide application menu item (macOS)
*/
static hide(): PredefinedMenuItem;
/**
* Hide other applications menu item (macOS)
*/
static hideOthers(): PredefinedMenuItem;
/**
* Show all applications menu item (macOS)
*/
static showAll(): PredefinedMenuItem;
/**
* Close window menu item
*/
static closeWindow(): PredefinedMenuItem;
/**
* Quit application menu item
*/
static quit(): PredefinedMenuItem;
/**
* About application menu item
* @param metadata - Optional about dialog metadata
*/
static about(metadata?: AboutMetadata): PredefinedMenuItem;
/**
* Services submenu (macOS)
*/
static services(): PredefinedMenuItem;
}
interface AboutMetadata {
name?: string;
version?: string;
shortVersion?: string;
authors?: string[];
comments?: string;
copyright?: string;
license?: string;
website?: string;
websiteLabel?: string;
credits?: string;
icon?: Image;
}
/**
* Menu icon types
*/
type MenuIcon = NativeIcon | string | Image | Uint8Array | ArrayBuffer | number[];
enum NativeIcon {
Add = 'add',
Advanced = 'advanced',
Bluetooth = 'bluetooth',
Bookmarks = 'bookmarks',
Caution = 'caution',
ColorPanel = 'colorPanel',
ColumnView = 'columnView',
Computer = 'computer',
EnterFullScreen = 'enterFullScreen',
Everyone = 'everyone',
ExitFullScreen = 'exitFullScreen',
FlowView = 'flowView',
Folder = 'folder',
FolderBurnable = 'folderBurnable',
FolderSmart = 'folderSmart',
FollowLinkFreestanding = 'followLinkFreestanding',
FontPanel = 'fontPanel',
GoLeft = 'goLeft',
GoRight = 'goRight',
Home = 'home',
IChatTheater = 'iChatTheater',
IconView = 'iconView',
Info = 'info',
InvalidDataFreestanding = 'invalidDataFreestanding',
LeftFacingTriangle = 'leftFacingTriangle',
ListView = 'listView',
LockLocked = 'lockLocked',
LockUnlocked = 'lockUnlocked',
MenuMixedState = 'menuMixedState',
MenuOnState = 'menuOnState',
MobileMe = 'mobileMe',
MultipleDocuments = 'multipleDocuments',
Network = 'network',
Path = 'path',
PreferencesGeneral = 'preferencesGeneral',
QuickLook = 'quickLook',
RefreshFreestanding = 'refreshFreestanding',
Refresh = 'refresh',
RefreshTemplate = 'refreshTemplate',
Remove = 'remove',
RevealFreestanding = 'revealFreestanding',
RightFacingTriangle = 'rightFacingTriangle',
Share = 'share',
Slideshow = 'slideshow',
SmartBadge = 'smartBadge',
StatusAvailable = 'statusAvailable',
StatusNone = 'statusNone',
StatusPartiallyAvailable = 'statusPartiallyAvailable',
StatusUnavailable = 'statusUnavailable',
StopProgressFreestanding = 'stopProgressFreestanding',
StopProgress = 'stopProgress',
StopProgressTemplate = 'stopProgressTemplate',
TrashEmpty = 'trashEmpty',
TrashFull = 'trashFull',
User = 'user',
UserAccounts = 'userAccounts',
UserGroup = 'userGroup',
UserGuest = 'userGuest'
}Manage application data stores on Apple platforms.
/**
* Data store identifier (array of 16 numbers)
*/
type DataStoreIdentifier = number[];
/**
* Fetch all data store identifiers
* @returns Array of data store identifiers
*/
function fetchDataStoreIdentifiers(): Promise<DataStoreIdentifier[]>;
/**
* Remove a specific data store
* @param uuid - Data store identifier to remove
* @returns Updated array of remaining data store identifiers
*/
function removeDataStore(uuid: DataStoreIdentifier): Promise<DataStoreIdentifier[]>;import { getVersion, getName, getTauriVersion } from '@tauri-apps/api/app';
// Get application metadata
const appVersion = await getVersion();
const appName = await getName();
const tauriVersion = await getTauriVersion();
console.log(`${appName} v${appVersion} (Tauri ${tauriVersion})`);
// Set application theme
import { setTheme } from '@tauri-apps/api/app';
await setTheme('dark');import { TrayIcon } from '@tauri-apps/api/tray';
import { Menu, MenuItem, PredefinedMenuItem } from '@tauri-apps/api/menu';
// Create tray menu
const menu = await Menu.new();
await menu.append([
await MenuItem.new('Show Window', true, 'Ctrl+Shift+S'),
await PredefinedMenuItem.separator(),
await MenuItem.new('Settings', true, 'Ctrl+,'),
await PredefinedMenuItem.separator(),
await PredefinedMenuItem.quit()
]);
// Create tray icon
const tray = await TrayIcon.new({
id: 'main-tray',
icon: '/path/to/tray-icon.png',
tooltip: 'My Application',
menu: menu
});
// Handle tray events
await tray.listen('click', (event) => {
if (event.button === 'Left') {
// Show/hide main window
toggleMainWindow();
}
});
// Update tray dynamically
await tray.setTitle('New Status');
await tray.setTooltip('Updated tooltip');import { Menu, Submenu, MenuItem, PredefinedMenuItem } from '@tauri-apps/api/menu';
// Create application menu
const menu = await Menu.new();
// File menu
const fileMenu = await Submenu.new('File');
await fileMenu.append([
await MenuItem.new('New', true, 'Ctrl+N'),
await MenuItem.new('Open', true, 'Ctrl+O'),
await MenuItem.new('Save', true, 'Ctrl+S'),
await PredefinedMenuItem.separator(),
await PredefinedMenuItem.quit()
]);
// Edit menu
const editMenu = await Submenu.new('Edit');
await editMenu.append([
await PredefinedMenuItem.undo(),
await PredefinedMenuItem.redo(),
await PredefinedMenuItem.separator(),
await PredefinedMenuItem.cut(),
await PredefinedMenuItem.copy(),
await PredefinedMenuItem.paste(),
await PredefinedMenuItem.selectAll()
]);
// Add menus to main menu
await menu.append([fileMenu, editMenu]);
// Set as application menu
await menu.setAsAppMenu();import { Menu, MenuItem, CheckMenuItem } from '@tauri-apps/api/menu';
// Create context menu
const contextMenu = await Menu.new();
await contextMenu.append([
await MenuItem.new('Copy', true, 'Ctrl+C'),
await MenuItem.new('Paste', true, 'Ctrl+V'),
await PredefinedMenuItem.separator(),
await CheckMenuItem.new('Show Grid', true, false),
await CheckMenuItem.new('Show Rulers', true, true)
]);
// Show context menu on right-click
document.addEventListener('contextmenu', async (e) => {
e.preventDefault();
await contextMenu.popup({ x: e.clientX, y: e.clientY });
});import { MenuItem } from '@tauri-apps/api/menu';
const saveItem = await MenuItem.new('Save', true, 'Ctrl+S');
// Listen for menu item activation
await saveItem.listen('click', () => {
console.log('Save menu item clicked');
// Perform save operation
});
// Update menu item state
await saveItem.setEnabled(false); // Disable when nothing to save
await saveItem.setText('Save *'); // Indicate unsaved changesimport { setDockVisibility, show, hide } from '@tauri-apps/api/app';
import { getBundleType, BundleType } from '@tauri-apps/api/app';
// macOS-specific features
if (process.platform === 'darwin') {
// Hide from dock when minimized
await setDockVisibility(false);
// Handle application show/hide
await hide(); // Hide application
await show(); // Show application
}
// Check installation type
const bundleType = await getBundleType();
if (bundleType === BundleType.AppImage) {
console.log('Running as AppImage on Linux');
} else if (bundleType === BundleType.Msi) {
console.log('Installed via MSI on Windows');
}Install with Tessl CLI
npx tessl i tessl/npm-tauri-apps--api