# Torch Control the device flashlight (torch) on Android and iOS. On Android, turning on the torch while another component holds the camera normally fails. This plugin also works while a [barcode scanner](../barcode-scanner) scan is running, so apps can offer a flashlight button in their scanning UI. | Platform | Supported | | -------- | --------- | | Linux | x | | Windows | x | | macOS | x | | Android | ✓ | | iOS | ✓ | ## Install _This plugin requires a Rust version of at least **1.90**_ There are three general methods of installation that we can recommend. 1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked) 2. Pull sources directly from Github using git tags / revision hashes (most secure) 3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use) Install the Core plugin by adding the following to your `Cargo.toml` file: `src-tauri/Cargo.toml` ```toml [dependencies] tauri-plugin-torch = "2.0.0" # alternatively with Git: tauri-plugin-torch = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } ``` You can install the JavaScript Guest bindings using your preferred JavaScript package manager: ```sh pnpm add @tauri-apps/plugin-torch # or npm add @tauri-apps/plugin-torch # or yarn add @tauri-apps/plugin-torch ``` ## Usage First you need to register the core plugin with Tauri: `src-tauri/src/lib.rs` ```rust fn main() { tauri::Builder::default() .plugin(tauri_plugin_torch::init()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } ``` Second, add the required permissions in the project: `src-tauri/capabilities/default.json` ```json "permissions": ["torch:default"] ``` Afterwards all the plugin's APIs are available through the JavaScript guest bindings: ```javascript import { enable, disable, toggle, isAvailable, isEnabled } from '@tauri-apps/plugin-torch' if (await isAvailable()) { await enable() console.log(await isEnabled()) // true await toggle() // returns false, the torch is now off await disable() } ``` `isEnabled` reads the hardware state, so it also reflects the torch being turned off by the system, another app, or a barcode scan ending. On iOS, apps can't see the torch state set by Control Center or another app: while the flashlight is on from there, `isEnabled` returns `false` and `toggle` tries to turn the torch on. ## Contributing PRs accepted. Please make sure to read the Contributing Guide before making a pull request. ## Partners
|
|