CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tauri-apps--api

TypeScript/JavaScript API bindings for Tauri applications providing comprehensive desktop app functionality

Pending
Overview
Eval results
Files

app-lifecycle.mddocs/

Application Lifecycle & Metadata

The app module provides APIs for managing application lifecycle, retrieving metadata, and controlling application-level behavior across platforms.

Capabilities

Application Metadata

Retrieve information about the current application.

/**
 * Get the application version
 * @returns Promise resolving to version string
 */
function getVersion(): Promise<string>;

/**
 * Get the application name
 * @returns Promise resolving to app name
 */
function getName(): Promise<string>;

/**
 * Get the Tauri version being used
 * @returns Promise resolving to Tauri version string
 */
function getTauriVersion(): Promise<string>;

/**
 * Get the application identifier
 * @returns Promise resolving to app identifier
 */
function getIdentifier(): Promise<string>;

/**
 * Get the bundle type of the current application
 * @returns Promise resolving to bundle type
 */
function getBundleType(): Promise<BundleType>;

enum BundleType {
  /** Windows NSIS */
  Nsis = 'nsis',
  /** Windows MSI */
  Msi = 'msi',
  /** Linux Debian package */
  Deb = 'deb',
  /** Linux RPM package */
  Rpm = 'rpm',
  /** Linux AppImage */
  AppImage = 'appimage',
  /** macOS app bundle */
  App = 'app'
}

Usage Examples:

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

// Get basic app information
const appName = await getName();
const appVersion = await getVersion();
const tauriVersion = await getTauriVersion();

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

// Check bundle type for platform-specific behavior
const bundleType = await getBundleType();
if (bundleType === BundleType.App) {
  console.log('Running on macOS');
} else if (bundleType === BundleType.Nsis || bundleType === BundleType.Msi) {
  console.log('Running on Windows');
}

Application Visibility

Control application visibility and focus, particularly on macOS.

/**
 * Show the application (macOS only)
 * Does not automatically focus any specific window
 * @returns Promise that resolves when operation completes
 */
function show(): Promise<void>;

/**
 * Hide the application (macOS only)
 * @returns Promise that resolves when operation completes
 */
function hide(): Promise<void>;

Usage Examples:

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

// Show application in dock (macOS)
await show();

// Hide application from dock (macOS)
await hide();

Application Theming

Control the application's theme appearance.

/**
 * Set the application theme
 * @param theme - Theme to apply ('light', 'dark', or null for system default)
 * @returns Promise that resolves when theme is applied
 */
function setTheme(theme?: Theme | null): Promise<void>;

type Theme = 'light' | 'dark';

Usage Examples:

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

// Set dark theme
await setTheme('dark');

// Set light theme
await setTheme('light');

// Use system theme
await setTheme(null);

Dock Management

Control dock visibility and behavior on macOS.

/**
 * Set dock icon visibility (macOS only)
 * @param visible - Whether dock icon should be visible
 * @returns Promise that resolves when visibility is set
 */
function setDockVisibility(visible: boolean): Promise<void>;

Usage Examples:

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

// Hide from dock (useful for background/menu bar apps)
await setDockVisibility(false);

// Show in dock
await setDockVisibility(true);

Application Icon

Access the default window icon for the application.

/**
 * Get the default window icon
 * @returns Promise resolving to Image instance or null if no icon
 */
function defaultWindowIcon(): Promise<Image | null>;

Usage Example:

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

const icon = await defaultWindowIcon();
if (icon) {
  const size = await icon.size();
  console.log(`Default icon size: ${size.width}x${size.height}`);
}

Data Store Management

Manage application data stores and their lifecycle.

/**
 * Get identifiers for all data stores
 * @returns Promise resolving to array of data store identifiers
 */
function fetchDataStoreIdentifiers(): Promise<DataStoreIdentifier[]>;

/**
 * Remove a data store
 * @param identifier - Data store identifier to remove
 * @returns Promise that resolves when store is removed
 */
function removeDataStore(identifier: DataStoreIdentifier): Promise<void>;

type DataStoreIdentifier = [
  number, number, number, number,
  number, number, number, number,
  number, number, number, number,
  number, number, number, number
];

Usage Examples:

import { fetchDataStoreIdentifiers, removeDataStore } from '@tauri-apps/api/app';

// List all data stores
const stores = await fetchDataStoreIdentifiers();
console.log(`Found ${stores.length} data stores`);

// Remove a specific data store
if (stores.length > 0) {
  await removeDataStore(stores[0]);
  console.log('Removed first data store');
}

Platform-Specific Behavior

macOS

  • show() and hide() control application visibility in dock
  • setDockVisibility() can create menu bar only applications
  • Theme changes affect system-wide appearance in some cases

Windows

  • show() and hide() have limited effect, primarily for integration scenarios
  • setDockVisibility() is a no-op

Linux

  • Most visibility functions are no-ops or have limited effect
  • Behavior depends on desktop environment

Error Handling

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

try {
  const name = await getName();
  await show();
} catch (error) {
  // Common error scenarios:
  // - Permission denied
  // - Platform not supported
  // - Application state conflicts
  console.error('App operation failed:', error);
}

Integration Examples

import { getName, getVersion, setTheme, setDockVisibility } from '@tauri-apps/api/app';
import { getCurrentWindow } from '@tauri-apps/api/window';

// Create a menu bar app
async function setupMenuBarApp() {
  await setDockVisibility(false);
  
  const window = getCurrentWindow();
  await window.setSkipTaskbar(true);
  await window.setAlwaysOnTop(true);
}

// Setup app info display
async function displayAppInfo() {
  const name = await getName();
  const version = await getVersion();
  
  document.title = `${name} v${version}`;
}

// Theme synchronization
async function syncTheme() {
  const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
  await setTheme(prefersDark ? 'dark' : 'light');
}

Install with Tessl CLI

npx tessl i tessl/npm-tauri-apps--api

docs

app-lifecycle.md

core-ipc.md

events.md

index.md

menu-system.md

system-integration.md

testing.md

utilities.md

window-management.md

tile.json