Skip to main content

Crate tauri_plugin

Crate tauri_plugin 

Source
Expand description

Interface for building Tauri plugins.

A Tauri plugin is a Rust crate that extends a Tauri application with commands, state, lifecycle hooks and - optionally - Android and iOS native code. This crate holds the pieces of that interface that are not part of the tauri crate itself, split in two Cargo features:

  • build: helpers for the plugin build.rs. Builder checks the crate against the Tauri plugin conventions (the links key must be set and match the crate name, the name cannot contain underscores or be a reserved one), autogenerates the allow-$command/deny-$command permissions for the plugin commands, parses the permission files, generates their JSON schema and reference documentation, defines the global scope schema and links the Android/iOS projects of the plugin. plugin_config reads the plugin configuration the Tauri CLI forwards to the build script, and the mobile module has helpers to patch the generated iOS Info.plist and entitlements and the Android manifest.
  • runtime: reserved for the runtime side of the plugin interface. It currently exports nothing - use tauri::plugin to define the plugin itself.

§Examples

A typical plugin build.rs:

ⓘ
const COMMANDS: &[&str] = &["ping", "execute"];

fn main() {
  tauri_plugin::Builder::new(COMMANDS)
    .android_path("android")
    .ios_path("ios")
    .build();
}

With a configuration type and an iOS Info.plist change:

ⓘ
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct Config {
  camera_usage_description: Option<String>,
}

fn main() {
  if let Some(config) = tauri_plugin::plugin_config::<Config>("my-plugin") {
    if let Some(description) = config.camera_usage_description {
      tauri_plugin::mobile::update_info_plist(|plist| {
        plist.insert("NSCameraUsageDescription".into(), description.into());
      })
      .expect("failed to update Info.plist");
    }
  }

  tauri_plugin::Builder::new(&["take_picture"]).build();
}

Modules§

mobilebuild
Mobile-specific build utilities.

Structs§

Builderbuild
Builder of the Tauri plugin build script.

Functions§

plugin_configbuild
Reads the configuration of the plugin with the given name from the environment.