or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

app-lifecycle.mdcore-ipc.mdevents.mdindex.mdmenu-system.mdsystem-integration.mdtesting.mdutilities.mdwindow-management.md

system-integration.mddocs/

0

# System Integration

1

2

Native desktop integration features including application lifecycle management, system tray icons, context menus, and platform-specific functionality for seamless desktop experience.

3

4

## Capabilities

5

6

### Application Lifecycle

7

8

Core application information and lifecycle management.

9

10

```typescript { .api }

11

/**

12

* Get application version from config

13

* @returns Application version string

14

*/

15

function getVersion(): Promise<string>;

16

17

/**

18

* Get application name from config

19

* @returns Application name string

20

*/

21

function getName(): Promise<string>;

22

23

/**

24

* Get Tauri framework version

25

* @returns Tauri version string

26

*/

27

function getTauriVersion(): Promise<string>;

28

29

/**

30

* Get application identifier from config

31

* @returns Application identifier string

32

*/

33

function getIdentifier(): Promise<string>;

34

35

/**

36

* Show application in dock/taskbar (macOS specific)

37

*/

38

function show(): Promise<void>;

39

40

/**

41

* Hide application from dock/taskbar (macOS specific)

42

*/

43

function hide(): Promise<void>;

44

45

/**

46

* Get the default window icon

47

* @returns Default icon or null if not set

48

*/

49

function defaultWindowIcon(): Promise<Image | null>;

50

51

/**

52

* Set application theme

53

* @param theme - Theme to apply ('light', 'dark', 'auto', or null for system)

54

*/

55

function setTheme(theme?: Theme | null): Promise<void>;

56

57

/**

58

* Set dock visibility (macOS specific)

59

* @param visible - Whether dock should be visible

60

*/

61

function setDockVisibility(visible: boolean): Promise<void>;

62

63

/**

64

* Get the installation bundle type

65

* @returns Bundle type used for this installation

66

*/

67

function getBundleType(): Promise<BundleType>;

68

69

type Theme = 'light' | 'dark' | 'auto';

70

enum BundleType {

71

Nsis = 'nsis',

72

Msi = 'msi',

73

Deb = 'deb',

74

Rpm = 'rpm',

75

AppImage = 'appImage',

76

App = 'app'

77

}

78

```

79

80

### System Tray Management

81

82

System tray icon management with support for icons, menus, and event handling.

83

84

```typescript { .api }

85

/**

86

* System tray icon management

87

*/

88

class TrayIcon {

89

/**

90

* Create a new system tray icon

91

* @param options - Tray icon configuration

92

* @returns Promise resolving to TrayIcon instance

93

*/

94

static new(options: TrayIconOptions): Promise<TrayIcon>;

95

96

/**

97

* Get tray icon by ID

98

* @param id - Tray icon identifier

99

* @returns TrayIcon instance or null if not found

100

*/

101

static getById(id: string): Promise<TrayIcon | null>;

102

103

/**

104

* Remove tray icon by ID

105

* @param id - Tray icon identifier

106

* @returns true if removed successfully

107

*/

108

static removeById(id: string): Promise<boolean>;

109

110

/**

111

* Set the tray icon image

112

* @param icon - Icon image, path, or null to remove

113

*/

114

setIcon(icon: Image | string | null): Promise<void>;

115

116

/**

117

* Set the tray icon context menu

118

* @param menu - Menu to show on right-click, or null to remove

119

*/

120

setMenu(menu: Menu | null): Promise<void>;

121

122

/**

123

* Set the tray icon tooltip text

124

* @param tooltip - Tooltip text or null to remove

125

*/

126

setTooltip(tooltip: string | null): Promise<void>;

127

128

/**

129

* Set the tray icon title (macOS only)

130

* @param title - Title text or null to remove

131

*/

132

setTitle(title: string | null): Promise<void>;

133

134

/**

135

* Set tray icon visibility

136

* @param visible - Whether the icon should be visible

137

*/

138

setVisible(visible: boolean): Promise<void>;

139

140

/**

141

* Set temporary directory path for tray icon assets

142

* @param path - Directory path or null to use default

143

*/

144

setTempDirPath(path: string | null): Promise<void>;

145

146

/**

147

* Set whether icon should be treated as template (macOS only)

148

* @param asTemplate - Whether to use template rendering

149

*/

150

setIconAsTemplate(asTemplate: boolean): Promise<void>;

151

152

/**

153

* Set whether menu shows on left click instead of right click

154

* @param onLeft - Whether to show menu on left click

155

*/

156

setMenuOnLeftClick(onLeft: boolean): Promise<void>;

157

}

158

159

interface TrayIconOptions {

160

/** Unique identifier for the tray icon */

161

id?: string;

162

/** Icon image or path */

163

icon?: Image | string;

164

/** Context menu */

165

menu?: Menu;

166

/** Tooltip text */

167

tooltip?: string;

168

/** Title text (macOS only) */

169

title?: string;

170

/** Menu position preference */

171

menuOnLeftClick?: boolean;

172

/** Icon template mode (macOS only) */

173

iconAsTemplate?: boolean;

174

/** Temporary directory for assets */

175

tempDirPath?: string;

176

}

177

```

178

179

### Tray Events

180

181

Handle tray icon interactions and events.

182

183

```typescript { .api }

184

/**

185

* Tray icon event types

186

*/

187

type TrayIconEvent =

188

| { type: 'Click'; position: PhysicalPosition; size: PhysicalSize; button: MouseButton; buttonState: MouseButtonState }

189

| { type: 'DoubleClick'; position: PhysicalPosition; size: PhysicalSize; button: MouseButton; buttonState: MouseButtonState }

190

| { type: 'Enter'; position: PhysicalPosition; size: PhysicalSize }

191

| { type: 'Move'; position: PhysicalPosition; size: PhysicalSize }

192

| { type: 'Leave'; position: PhysicalPosition; size: PhysicalSize };

193

194

type MouseButton = 'Left' | 'Right' | 'Middle';

195

type MouseButtonState = 'Up' | 'Down';

196

```

197

198

### Menu System

199

200

Comprehensive menu system for application menus, context menus, and tray menus.

201

202

```typescript { .api }

203

/**

204

* Menu container for organizing menu items

205

*/

206

class Menu {

207

/**

208

* Create a new empty menu

209

* @returns Promise resolving to Menu instance

210

*/

211

static new(): Promise<Menu>;

212

213

/**

214

* Append items to the menu

215

* @param items - Menu item or array of menu items to append

216

*/

217

append(items: MenuItem | MenuItem[]): Promise<void>;

218

219

/**

220

* Prepend items to the menu

221

* @param items - Menu item or array of menu items to prepend

222

*/

223

prepend(items: MenuItem | MenuItem[]): Promise<void>;

224

225

/**

226

* Insert items at specific position

227

* @param items - Menu item or array of menu items to insert

228

* @param position - Index position to insert at

229

*/

230

insert(items: MenuItem | MenuItem[], position: number): Promise<void>;

231

232

/**

233

* Remove item at specific position

234

* @param position - Index of item to remove

235

*/

236

remove(position: number): Promise<void>;

237

238

/**

239

* Remove all items from the menu

240

*/

241

removeAll(): Promise<void>;

242

243

/**

244

* Get all items in the menu

245

* @returns Array of menu items

246

*/

247

items(): Promise<MenuItem[]>;

248

249

/**

250

* Get item at specific position

251

* @param position - Index of item to get

252

* @returns Menu item or null if not found

253

*/

254

get(position: number): Promise<MenuItem | null>;

255

256

/**

257

* Show menu as popup at specified position

258

* @param position - Position to show popup, or null for cursor position

259

*/

260

popup(position?: Position): Promise<void>;

261

262

/**

263

* Set this menu as the application menu (macOS/Linux)

264

*/

265

setAsAppMenu(): Promise<void>;

266

267

/**

268

* Set this menu as the window menu (Windows)

269

*/

270

setAsWindowMenu(): Promise<void>;

271

}

272

```

273

274

### Menu Items

275

276

Various types of menu items with different behaviors and properties.

277

278

```typescript { .api }

279

/**

280

* Base menu item interface

281

*/

282

interface MenuItemBase {

283

text(): Promise<string>;

284

setText(text: string): Promise<void>;

285

isEnabled(): Promise<boolean>;

286

setEnabled(enabled: boolean): Promise<void>;

287

setAccelerator(accelerator: string | null): Promise<void>;

288

}

289

290

/**

291

* Regular clickable menu item

292

*/

293

class MenuItem implements MenuItemBase {

294

/**

295

* Create a new menu item

296

* @param text - Display text

297

* @param enabled - Whether item is enabled

298

* @param accelerator - Keyboard shortcut (e.g., "Ctrl+N")

299

*/

300

constructor(text: string, enabled?: boolean, accelerator?: string);

301

302

text(): Promise<string>;

303

setText(text: string): Promise<void>;

304

isEnabled(): Promise<boolean>;

305

setEnabled(enabled: boolean): Promise<void>;

306

setAccelerator(accelerator: string | null): Promise<void>;

307

}

308

309

/**

310

* Checkable menu item with toggle state

311

*/

312

class CheckMenuItem implements MenuItemBase {

313

/**

314

* Create a new check menu item

315

* @param text - Display text

316

* @param enabled - Whether item is enabled

317

* @param checked - Initial checked state

318

* @param accelerator - Keyboard shortcut

319

*/

320

constructor(text: string, enabled?: boolean, checked?: boolean, accelerator?: string);

321

322

text(): Promise<string>;

323

setText(text: string): Promise<void>;

324

isEnabled(): Promise<boolean>;

325

setEnabled(enabled: boolean): Promise<void>;

326

setAccelerator(accelerator: string | null): Promise<void>;

327

328

/**

329

* Get checked state

330

* @returns true if checked

331

*/

332

isChecked(): Promise<boolean>;

333

334

/**

335

* Set checked state

336

* @param checked - Whether item should be checked

337

*/

338

setChecked(checked: boolean): Promise<void>;

339

}

340

341

/**

342

* Menu item with icon

343

*/

344

class IconMenuItem implements MenuItemBase {

345

/**

346

* Create a new icon menu item

347

* @param text - Display text

348

* @param enabled - Whether item is enabled

349

* @param accelerator - Keyboard shortcut

350

* @param icon - Menu icon

351

*/

352

constructor(text: string, enabled?: boolean, accelerator?: string, icon?: MenuIcon);

353

354

text(): Promise<string>;

355

setText(text: string): Promise<void>;

356

isEnabled(): Promise<boolean>;

357

setEnabled(enabled: boolean): Promise<void>;

358

setAccelerator(accelerator: string | null): Promise<void>;

359

360

/**

361

* Set the menu item icon

362

* @param icon - Icon to set or null to remove

363

*/

364

setIcon(icon: MenuIcon | null): Promise<void>;

365

}

366

367

/**

368

* Submenu container

369

*/

370

class Submenu implements MenuItemBase {

371

/**

372

* Create a new submenu

373

* @param text - Display text

374

* @param enabled - Whether submenu is enabled

375

*/

376

constructor(text: string, enabled?: boolean);

377

378

text(): Promise<string>;

379

setText(text: string): Promise<void>;

380

isEnabled(): Promise<boolean>;

381

setEnabled(enabled: boolean): Promise<void>;

382

setAccelerator(accelerator: string | null): Promise<void>;

383

384

/**

385

* Append items to the submenu

386

* @param items - Menu item or array of items to append

387

*/

388

append(items: MenuItem | MenuItem[]): Promise<void>;

389

390

/**

391

* Prepend items to the submenu

392

* @param items - Menu item or array of items to prepend

393

*/

394

prepend(items: MenuItem | MenuItem[]): Promise<void>;

395

396

/**

397

* Insert items at specific position

398

* @param items - Menu item or array of items to insert

399

* @param position - Index position to insert at

400

*/

401

insert(items: MenuItem | MenuItem[], position: number): Promise<void>;

402

403

/**

404

* Remove item at specific position

405

* @param position - Index of item to remove

406

*/

407

remove(position: number): Promise<void>;

408

409

/**

410

* Get all items in the submenu

411

* @returns Array of menu items

412

*/

413

items(): Promise<MenuItem[]>;

414

}

415

416

/**

417

* Platform-specific predefined menu items

418

*/

419

class PredefinedMenuItem {

420

/**

421

* Menu separator

422

*/

423

static separator(): PredefinedMenuItem;

424

425

/**

426

* Copy menu item (Ctrl+C/Cmd+C)

427

*/

428

static copy(): PredefinedMenuItem;

429

430

/**

431

* Cut menu item (Ctrl+X/Cmd+X)

432

*/

433

static cut(): PredefinedMenuItem;

434

435

/**

436

* Paste menu item (Ctrl+V/Cmd+V)

437

*/

438

static paste(): PredefinedMenuItem;

439

440

/**

441

* Select All menu item (Ctrl+A/Cmd+A)

442

*/

443

static selectAll(): PredefinedMenuItem;

444

445

/**

446

* Undo menu item (Ctrl+Z/Cmd+Z)

447

*/

448

static undo(): PredefinedMenuItem;

449

450

/**

451

* Redo menu item (Ctrl+Y/Cmd+Shift+Z)

452

*/

453

static redo(): PredefinedMenuItem;

454

455

/**

456

* Minimize window menu item

457

*/

458

static minimize(): PredefinedMenuItem;

459

460

/**

461

* Hide application menu item (macOS)

462

*/

463

static hide(): PredefinedMenuItem;

464

465

/**

466

* Hide other applications menu item (macOS)

467

*/

468

static hideOthers(): PredefinedMenuItem;

469

470

/**

471

* Show all applications menu item (macOS)

472

*/

473

static showAll(): PredefinedMenuItem;

474

475

/**

476

* Close window menu item

477

*/

478

static closeWindow(): PredefinedMenuItem;

479

480

/**

481

* Quit application menu item

482

*/

483

static quit(): PredefinedMenuItem;

484

485

/**

486

* About application menu item

487

* @param metadata - Optional about dialog metadata

488

*/

489

static about(metadata?: AboutMetadata): PredefinedMenuItem;

490

491

/**

492

* Services submenu (macOS)

493

*/

494

static services(): PredefinedMenuItem;

495

}

496

497

interface AboutMetadata {

498

name?: string;

499

version?: string;

500

shortVersion?: string;

501

authors?: string[];

502

comments?: string;

503

copyright?: string;

504

license?: string;

505

website?: string;

506

websiteLabel?: string;

507

credits?: string;

508

icon?: Image;

509

}

510

511

/**

512

* Menu icon types

513

*/

514

type MenuIcon = NativeIcon | string | Image | Uint8Array | ArrayBuffer | number[];

515

516

enum NativeIcon {

517

Add = 'add',

518

Advanced = 'advanced',

519

Bluetooth = 'bluetooth',

520

Bookmarks = 'bookmarks',

521

Caution = 'caution',

522

ColorPanel = 'colorPanel',

523

ColumnView = 'columnView',

524

Computer = 'computer',

525

EnterFullScreen = 'enterFullScreen',

526

Everyone = 'everyone',

527

ExitFullScreen = 'exitFullScreen',

528

FlowView = 'flowView',

529

Folder = 'folder',

530

FolderBurnable = 'folderBurnable',

531

FolderSmart = 'folderSmart',

532

FollowLinkFreestanding = 'followLinkFreestanding',

533

FontPanel = 'fontPanel',

534

GoLeft = 'goLeft',

535

GoRight = 'goRight',

536

Home = 'home',

537

IChatTheater = 'iChatTheater',

538

IconView = 'iconView',

539

Info = 'info',

540

InvalidDataFreestanding = 'invalidDataFreestanding',

541

LeftFacingTriangle = 'leftFacingTriangle',

542

ListView = 'listView',

543

LockLocked = 'lockLocked',

544

LockUnlocked = 'lockUnlocked',

545

MenuMixedState = 'menuMixedState',

546

MenuOnState = 'menuOnState',

547

MobileMe = 'mobileMe',

548

MultipleDocuments = 'multipleDocuments',

549

Network = 'network',

550

Path = 'path',

551

PreferencesGeneral = 'preferencesGeneral',

552

QuickLook = 'quickLook',

553

RefreshFreestanding = 'refreshFreestanding',

554

Refresh = 'refresh',

555

RefreshTemplate = 'refreshTemplate',

556

Remove = 'remove',

557

RevealFreestanding = 'revealFreestanding',

558

RightFacingTriangle = 'rightFacingTriangle',

559

Share = 'share',

560

Slideshow = 'slideshow',

561

SmartBadge = 'smartBadge',

562

StatusAvailable = 'statusAvailable',

563

StatusNone = 'statusNone',

564

StatusPartiallyAvailable = 'statusPartiallyAvailable',

565

StatusUnavailable = 'statusUnavailable',

566

StopProgressFreestanding = 'stopProgressFreestanding',

567

StopProgress = 'stopProgress',

568

StopProgressTemplate = 'stopProgressTemplate',

569

TrashEmpty = 'trashEmpty',

570

TrashFull = 'trashFull',

571

User = 'user',

572

UserAccounts = 'userAccounts',

573

UserGroup = 'userGroup',

574

UserGuest = 'userGuest'

575

}

576

```

577

578

### Data Store Management (iOS/macOS)

579

580

Manage application data stores on Apple platforms.

581

582

```typescript { .api }

583

/**

584

* Data store identifier (array of 16 numbers)

585

*/

586

type DataStoreIdentifier = number[];

587

588

/**

589

* Fetch all data store identifiers

590

* @returns Array of data store identifiers

591

*/

592

function fetchDataStoreIdentifiers(): Promise<DataStoreIdentifier[]>;

593

594

/**

595

* Remove a specific data store

596

* @param uuid - Data store identifier to remove

597

* @returns Updated array of remaining data store identifiers

598

*/

599

function removeDataStore(uuid: DataStoreIdentifier): Promise<DataStoreIdentifier[]>;

600

```

601

602

## Usage Examples

603

604

### Basic Application Information

605

606

```typescript

607

import { getVersion, getName, getTauriVersion } from '@tauri-apps/api/app';

608

609

// Get application metadata

610

const appVersion = await getVersion();

611

const appName = await getName();

612

const tauriVersion = await getTauriVersion();

613

614

console.log(`${appName} v${appVersion} (Tauri ${tauriVersion})`);

615

616

// Set application theme

617

import { setTheme } from '@tauri-apps/api/app';

618

await setTheme('dark');

619

```

620

621

### System Tray Integration

622

623

```typescript

624

import { TrayIcon } from '@tauri-apps/api/tray';

625

import { Menu, MenuItem, PredefinedMenuItem } from '@tauri-apps/api/menu';

626

627

// Create tray menu

628

const menu = await Menu.new();

629

await menu.append([

630

await MenuItem.new('Show Window', true, 'Ctrl+Shift+S'),

631

await PredefinedMenuItem.separator(),

632

await MenuItem.new('Settings', true, 'Ctrl+,'),

633

await PredefinedMenuItem.separator(),

634

await PredefinedMenuItem.quit()

635

]);

636

637

// Create tray icon

638

const tray = await TrayIcon.new({

639

id: 'main-tray',

640

icon: '/path/to/tray-icon.png',

641

tooltip: 'My Application',

642

menu: menu

643

});

644

645

// Handle tray events

646

await tray.listen('click', (event) => {

647

if (event.button === 'Left') {

648

// Show/hide main window

649

toggleMainWindow();

650

}

651

});

652

653

// Update tray dynamically

654

await tray.setTitle('New Status');

655

await tray.setTooltip('Updated tooltip');

656

```

657

658

### Application Menu (macOS/Linux)

659

660

```typescript

661

import { Menu, Submenu, MenuItem, PredefinedMenuItem } from '@tauri-apps/api/menu';

662

663

// Create application menu

664

const menu = await Menu.new();

665

666

// File menu

667

const fileMenu = await Submenu.new('File');

668

await fileMenu.append([

669

await MenuItem.new('New', true, 'Ctrl+N'),

670

await MenuItem.new('Open', true, 'Ctrl+O'),

671

await MenuItem.new('Save', true, 'Ctrl+S'),

672

await PredefinedMenuItem.separator(),

673

await PredefinedMenuItem.quit()

674

]);

675

676

// Edit menu

677

const editMenu = await Submenu.new('Edit');

678

await editMenu.append([

679

await PredefinedMenuItem.undo(),

680

await PredefinedMenuItem.redo(),

681

await PredefinedMenuItem.separator(),

682

await PredefinedMenuItem.cut(),

683

await PredefinedMenuItem.copy(),

684

await PredefinedMenuItem.paste(),

685

await PredefinedMenuItem.selectAll()

686

]);

687

688

// Add menus to main menu

689

await menu.append([fileMenu, editMenu]);

690

691

// Set as application menu

692

await menu.setAsAppMenu();

693

```

694

695

### Context Menu

696

697

```typescript

698

import { Menu, MenuItem, CheckMenuItem } from '@tauri-apps/api/menu';

699

700

// Create context menu

701

const contextMenu = await Menu.new();

702

await contextMenu.append([

703

await MenuItem.new('Copy', true, 'Ctrl+C'),

704

await MenuItem.new('Paste', true, 'Ctrl+V'),

705

await PredefinedMenuItem.separator(),

706

await CheckMenuItem.new('Show Grid', true, false),

707

await CheckMenuItem.new('Show Rulers', true, true)

708

]);

709

710

// Show context menu on right-click

711

document.addEventListener('contextmenu', async (e) => {

712

e.preventDefault();

713

await contextMenu.popup({ x: e.clientX, y: e.clientY });

714

});

715

```

716

717

### Menu Event Handling

718

719

```typescript

720

import { MenuItem } from '@tauri-apps/api/menu';

721

722

const saveItem = await MenuItem.new('Save', true, 'Ctrl+S');

723

724

// Listen for menu item activation

725

await saveItem.listen('click', () => {

726

console.log('Save menu item clicked');

727

// Perform save operation

728

});

729

730

// Update menu item state

731

await saveItem.setEnabled(false); // Disable when nothing to save

732

await saveItem.setText('Save *'); // Indicate unsaved changes

733

```

734

735

### Platform-Specific Features

736

737

```typescript

738

import { setDockVisibility, show, hide } from '@tauri-apps/api/app';

739

import { getBundleType, BundleType } from '@tauri-apps/api/app';

740

741

// macOS-specific features

742

if (process.platform === 'darwin') {

743

// Hide from dock when minimized

744

await setDockVisibility(false);

745

746

// Handle application show/hide

747

await hide(); // Hide application

748

await show(); // Show application

749

}

750

751

// Check installation type

752

const bundleType = await getBundleType();

753

if (bundleType === BundleType.AppImage) {

754

console.log('Running as AppImage on Linux');

755

} else if (bundleType === BundleType.Msi) {

756

console.log('Installed via MSI on Windows');

757

}

758

```