tauri_plugin/lib.rs
1// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5//! Interface for building Tauri plugins.
6//!
7//! A Tauri plugin is a Rust crate that extends a Tauri application with commands, state,
8//! lifecycle hooks and - optionally - Android and iOS native code. This crate holds the pieces
9//! of that interface that are not part of the [`tauri`] crate itself, split in two Cargo
10//! features:
11//!
12//! - **`build`**: helpers for the plugin `build.rs`. [`Builder`] checks the crate against the
13//! Tauri plugin conventions (the `links` key must be set and match the crate name, the name
14//! cannot contain underscores or be a reserved one), autogenerates the
15//! `allow-$command`/`deny-$command` permissions for the plugin commands, parses the
16//! permission files, generates their JSON schema and reference documentation, defines the
17//! global scope schema and links the Android/iOS projects of the plugin.
18//! [`plugin_config`] reads the plugin configuration the Tauri CLI forwards to the build
19//! script, and the [`mobile`] module has helpers to patch the generated iOS `Info.plist` and
20//! entitlements and the Android manifest.
21//! - **`runtime`**: reserved for the runtime side of the plugin interface. It currently
22//! exports nothing - use [`tauri::plugin`] to define the plugin itself.
23//!
24//! # Examples
25//!
26//! A typical plugin `build.rs`:
27//!
28//! ```rust,ignore
29//! const COMMANDS: &[&str] = &["ping", "execute"];
30//!
31//! fn main() {
32//! tauri_plugin::Builder::new(COMMANDS)
33//! .android_path("android")
34//! .ios_path("ios")
35//! .build();
36//! }
37//! ```
38//!
39//! With a configuration type and an iOS `Info.plist` change:
40//!
41//! ```rust,ignore
42//! #[derive(serde::Deserialize)]
43//! #[serde(rename_all = "camelCase")]
44//! struct Config {
45//! camera_usage_description: Option<String>,
46//! }
47//!
48//! fn main() {
49//! if let Some(config) = tauri_plugin::plugin_config::<Config>("my-plugin") {
50//! if let Some(description) = config.camera_usage_description {
51//! tauri_plugin::mobile::update_info_plist(|plist| {
52//! plist.insert("NSCameraUsageDescription".into(), description.into());
53//! })
54//! .expect("failed to update Info.plist");
55//! }
56//! }
57//!
58//! tauri_plugin::Builder::new(&["take_picture"]).build();
59//! }
60//! ```
61//!
62//! [`tauri`]: https://docs.rs/tauri/latest/tauri/
63//! [`tauri::plugin`]: https://docs.rs/tauri/latest/tauri/plugin/index.html
64//! [`Builder`]: https://docs.rs/tauri-plugin/latest/tauri_plugin/struct.Builder.html
65//! [`plugin_config`]: https://docs.rs/tauri-plugin/latest/tauri_plugin/fn.plugin_config.html
66//! [`mobile`]: https://docs.rs/tauri-plugin/latest/tauri_plugin/mobile/index.html
67
68#![doc(
69 html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/.github/icon.png",
70 html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/.github/icon.png"
71)]
72#![cfg_attr(docsrs, feature(doc_cfg))]
73
74#[cfg(feature = "build")]
75mod build;
76#[cfg(feature = "runtime")]
77mod runtime;
78
79#[cfg(feature = "build")]
80#[cfg_attr(docsrs, doc(cfg(feature = "build")))]
81pub use build::*;
82#[cfg(feature = "runtime")]
83#[cfg_attr(docsrs, doc(cfg(feature = "runtime")))]
84#[allow(unused)]
85pub use runtime::*;