Tauri 2.0 Documentation

repository·v2·Indexed 22 days ago

https://github.com/tauri-apps/tauri-docs

Official documentation for Tauri 2.0, covering the security model, polyglot architecture, and getting started guides. Includes technical details on building applications using various package managers (npm, yarn, pnpm, bun, deno, cargo) and guidelines for using TAURI, TAO, and WRY trademarks.

Tokens
169.5K
Snippets
543
Records
720
Agent score
77%

What's inside tauri-docs

  1. Introduction to Tauri 2.0

    v2

    Tauri 2.0 is a cross-platform application building toolkit designed to create small, fast, and secure applications. It allows developers to build apps for Linux, macOS, Windows, Android, and iOS from a single codebase.

    Key features include:

    • Frontend Independence: Use any existing web stack or frontend framework.
    • Cross-Platform Support: Target desktop (Linux, macOS, Windows) and mobile (Android, iOS) platforms.
    • Security-First Design: Built with a focus on maximum security.
    • Minimal Binary Size: Leverages the OS's native web renderer, allowing app sizes to be as small as 600KB.
  2. What is Tauri?

    v2

    Tauri is a toolkit for building cross-platform desktop applications. Key features include:

    • Core Engine: Written in Rust for performance and safety.
    • Frontend: Supports virtually any web framework.
    • JavaScript API: An optional, tree-shakeable API for low-level system access.
    • Bundler: Includes a desktop binary bundler with code signing and artifact verification.
    • Updater: A secure updater mechanism for maintaining user applications.
    • Extensibility: An extensive plugin system and support for OS-level integrations like notifications and app trays.
  3. Explore Tauri Core Concepts

    v2

    To build effective and secure applications with Tauri, developers should understand several foundational pillars:

    • Tauri Architecture: Understanding the overall ecosystem and how components interact.
    • Inter-Process Communication (IPC): Learning how the frontend and backend communicate.
    • Security: Understanding how Tauri enforces security practices and how to configure them.
    • Process Model: Understanding the different processes managed by Tauri and their roles.
    • App Size: Best practices for minimizing the final application footprint.
  4. Recommended JavaScript and Rust frameworks for Tauri

    v2

    Tauri supports a wide range of frontend technologies. While many work without extra configuration, certain frameworks require specific setups due to their architecture (e.g., SSR vs SSG).

    JavaScript/TypeScript

    For most projects, Vite is the recommended tool for SPAs (React, Vue, Svelte, Solid) and plain JS/TS projects. If using Meta-Frameworks, special configuration is typically required to disable SSR and enable SSG/SPA mode.

    Supported Meta-Frameworks:

    • Next.js
    • Nuxt
    • Qwik
    • SvelteKit

    Rust

    For Rust-based frontend development, the following are supported:

    • Leptos
    • Trunk
  5. Explore Tauri official features and community plugins

    v2

    Tauri is designed for extensibility. You can extend its functionality using two primary methods:

    1. Official Features: Built-in Tauri features and functionality provided by the core team.
    2. Community Resources: Plugins and recipes built by the Tauri community. You can find these in the community sections or contribute your own to the Awesome Tauri repository.

    Use the search and platform filtering tools on the documentation site to find specific features or plugins compatible with your target platforms.

  6. Tauri 2.0 Release Candidate Overview

    v2

    Tauri 2.0 has entered the Release Candidate (RC) phase. This stage indicates that the core API is considered stabilized, and no further breaking changes are expected before the stable release. The primary focus during the RC phase is documentation improvements and addressing critical bug fixes reported by the community.

    Key takeaways for developers:

    • Stability: Breaking changes are no longer expected.
    • Mobile Support: While mobile is not yet the primary focus of the 2.0 core, production-ready mobile applications can be developed using official mobile plugins (e.g., NFC, Barcode Scanner, Biometric, Haptics, Geolocation) available in the plugins-workspace repository.
    • Timeline: The stable release is targeted for late August following a ~4 week RC cycle.
  7. What is Tauri?

    v2

    Tauri is a framework designed to build small, fast binaries for desktop (macOS, Linux, Windows) and mobile (iOS, Android) platforms.

    Core Architecture

    • Frontend: Built using any web technology stack (HTML, JavaScript, CSS) and runs inside the operating system's native WebView.
    • Backend: The application core is primarily written in Rust, though developers can also leverage Swift (iOS) or Kotlin (Android) for native logic.
    • Communication: The frontend communicates with the Rust backend via an Inter-Process Communication (IPC) bridge.

    Key Benefits

    • No Rust required: While the core is Rust-based, Tauri provides an extensive JavaScript API that allows most developers to build applications without writing Rust, Swift, or Kotlin code.
  8. What is the Isolation pattern?

    v2

    The Isolation pattern is a security mechanism that intercepts and modifies Tauri API messages sent from the frontend before they reach Tauri Core. It uses a sandboxed <iframe> to run secure JavaScript code, known as the Isolation application, which acts as a gatekeeper between your untrusted frontend (and its dependencies) and the Tauri Core.

    Why use it?

    It protects your application from Development Threats, such as malicious or buggy code within deeply-nested frontend dependencies. By using the Isolation application, you can verify IPC inputs—for example, ensuring file system calls stay within expected directories or validating Origin headers in HTTP fetch calls.

    How it works

    1. The frontend sends an IPC message.
    2. The message is routed to the sandboxed Isolation application.
    3. The [sandbox] Isolation application hook runs, allowing you to inspect or modify the message.
    4. The message is encrypted using AES-GCM with a runtime-generated key (unique to each application run).
    5. The encrypted message is passed to Tauri Core, where it is decrypted and processed.
  9. Android WebView runtime behavior

    v2

    Tauri uses the system Android WebView (based on Chromium) on Android devices.

    • No Bundling: Tauri does not bundle a WebView with your application; the runtime version depends entirely on the device's currently selected WebView provider.
    • Updates: On most production devices, WebView is an updatable system component.
    • Version Checking:
      • To check the version used by a development build, open the Android Web Inspector and inspect the running WebView using Chrome DevTools.
      • Alternatively, check the selected WebView provider and app version within the device's Android developer settings.
  10. Tauri plugin naming conventions

    v2

    Tauri plugins follow a specific naming convention to ensure discoverability and compatibility with the Tauri CLI:

    1. Rust Crate Name: Prefixed with tauri-plugin- (e.g., tauri-plugin-my-plugin).
    2. NPM Package Name: Usually tauri-plugin-{plugin-name}-api. However, it is recommended to use an NPM scope, such as @scope-name/plugin-{plugin-name}.
    3. Configuration Key: The plugin name used in tauri.conf.json is the name specified in the plugin configuration.
  11. Configure Log targets in Rust

    v2

    The tauri_plugin_log::Builder allows you to specify where logs are sent using TargetKind. By default, logs go to stdout and a file in the application logs directory. Use .clear_targets() to remove defaults if you only want specific targets.

    Common Targets

    • Stdout/Stderr: Forward logs to the terminal.
    • Webview: View Rust logs in the browser/webview console. Requires calling attachConsole() in JavaScript.
    • LogDir: Write logs to the platform-recommended log directory.
    • Folder: Write logs to a custom filesystem path.
    // Example: Logging to a custom folder
    tauri_plugin_log::Builder::new()
      .target(tauri_plugin_log::Target::new(
        tauri_plugin_log::TargetKind::Folder {
          path: std::path::PathBuf::from("/path/to/logs"),
          file_name: None,
        },
      ))
      .build()