new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Tauri · Plugins and security · all subjects

plugin

184 notes in this subject, read out of this brain and free to use. This is page 2 of 4.

OS plugin permissions configuration

To enable the OS plugin, add 'os:default' to the permissions array in the capabilities configuration file (src-tauri/capabilities/default.json). By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed unless explicitly enabled.

OS plugin installation with automatic setup

The OS Information plugin can be installed automatically using the command 'npm run tauri add os', 'yarn run tauri add os', 'pnpm tauri add os', 'deno task tauri add os', 'bun tauri add os', or 'cargo tauri add os' depending on the package manager.

OS plugin manual installation steps

To manually install the OS plugin: (1) Run 'cargo add tauri-plugin-os' in the src-tauri folder to add it to Cargo.toml. (2) Modify src-tauri/src/lib.rs to add '.plugin(tauri_plugin_os::init())' in the tauri::Builder::default() chain. (3) If using JavaScript, install the npm package '@tauri-apps/plugin-os' using 'npm install @tauri-apps/plugin-os', 'yarn add @tauri-apps/plugin-os', 'pnpm add @tauri-apps/plugin-os', 'deno add npm:@tauri-apps/plugin-os', or 'bun add @tauri-apps/plugin-os'.

OS plugin platform() function returns

The platform() function returns a string describing the specific operating system in use, set at compile time. Possible values are: linux, macos, ios, freebsd, dragonfly, netbsd, openbsd, solaris, android, windows.

OS plugin JavaScript API example with platform()

Example showing how to use the platform() function in JavaScript: import { platform } from '@tauri-apps/plugin-os'; const currentPlatform = platform(); console.log(currentPlatform); // Prints operating system string like 'windows'

Process plugin setup - Automatic installation

To automatically add the process plugin, run one of these commands from your project root: npm run tauri add process, yarn run tauri add process, pnpm tauri add process, deno task tauri add process, bun tauri add process, or cargo tauri add process.

Process plugin setup - Manual installation

To manually add the process plugin: (1) Run 'cargo add tauri-plugin-process' in the src-tauri folder. (2) Modify src-tauri/src/lib.rs to add .plugin(tauri_plugin_process::init()) to the tauri::Builder::default() chain. (3) Optionally install the npm package for JavaScript support using npm install @tauri-apps/plugin-process, yarn add @tauri-apps/plugin-process, pnpm add @tauri-apps/plugin-process, deno add npm:@tauri-apps/plugin-process, or bun add @tauri-apps/plugin-process.

Process plugin JavaScript API - exit

In JavaScript, import exit from '@tauri-apps/plugin-process' or access via window.__TAURI__.process if 'withGlobalTauri' is true. Call await exit(0) to exit the app with the given status code.

Process plugin JavaScript API - relaunch

In JavaScript, import relaunch from '@tauri-apps/plugin-process' or access via window.__TAURI__.process if 'withGlobalTauri' is true. Call await relaunch() to restart the app.

Process plugin Rust API - exit

In Rust, call app.exit(0) where app is an AppHandle instance to exit the app with the given status code.

Process plugin Rust API - restart

In Rust, call app.restart() where app is an AppHandle instance to restart the app.

Process plugin permissions default capability

To enable the process plugin, add 'process:default' to the permissions array in src-tauri/capabilities/default.json.

Process plugin overview

The process plugin provides APIs to access the current process in Tauri applications. To spawn child processes, use the shell plugin instead.

Positioner plugin: tray-icon feature setup

To enable tray-relative positions, add the tray-icon feature to Cargo.toml: tauri-plugin-positioner = { version = "2.0.0", features = ["tray-icon"] }

Positioner plugin: JavaScript usage

The Positioner plugin JavaScript API is imported with: import { moveWindow, Position } from '@tauri-apps/plugin-positioner'; Call moveWindow with a Position enum value such as moveWindow(Position.TopRight);

Positioner plugin: JavaScript with global Tauri

When using "withGlobalTauri": true, access the Positioner API as: const { moveWindow, Position } = window.__TAURI__.positioner;

Positioner plugin: Rust usage

To use the Positioner plugin in Rust, import: use tauri_plugin_positioner::{WindowExt, Position}; Then call on a window: let mut win = app.get_webview_window("main").unwrap(); let _ = win.as_ref().window().move_window(Position::TopRight);

Positioner plugin: default permission requirement

The Positioner plugin requires the permission "positioner:default" to be enabled in the capabilities configuration file (src-tauri/capabilities/default.json).

Positioner plugin: Rust-only setup option

If only moving the window from Rust code, you only need the dependency in src-tauri/Cargo.toml, and can remove the plugin registration from lib.rs if you choose to setup automatically.

Positioner plugin: what it does

The Positioner plugin is a Tauri plugin that allows moving windows to well-known locations. It is a port of electron-positioner for Tauri.

Positioner plugin: automatic setup command

To automatically install the Positioner plugin, run: npm run tauri add positioner (npm), yarn run tauri add positioner (yarn), pnpm tauri add positioner (pnpm), bun tauri add positioner (bun), deno task tauri add positioner (deno), or cargo tauri add positioner (cargo).

Positioner plugin: manual Rust dependency setup

To manually add the Positioner plugin to Cargo.toml, run: cargo add tauri-plugin-positioner --target 'cfg(any(target_os = "macos", windows, target_os = "linux"))'

Positioner plugin: Rust lib.rs initialization

To initialize the Positioner plugin in lib.rs, add the following in the setup function: #[cfg(desktop)] app.handle().plugin(tauri_plugin_positioner::init());

Positioner plugin: JavaScript bindings installation

Install the JavaScript guest bindings using: npm install @tauri-apps/plugin-positioner (npm), yarn add @tauri-apps/plugin-positioner (yarn), pnpm add @tauri-apps/plugin-positioner (pnpm), deno add npm:@tauri-apps/plugin-positioner (deno), or bun add @tauri-apps/plugin-positioner (bun).

Positioner plugin: tray event handler setup

To handle tray events for positioner, set up on_tray_icon_event in the setup function: tauri::tray::TrayIconBuilder::new().on_tray_icon_event(|tray_handle, event| { tauri_plugin_positioner::on_tray_event(tray_handle.app_handle(), &event); }).build(app)?;

Shell plugin Rust usage example

Example Rust code showing how to use the shell plugin: use tauri_plugin_shell::ShellExt; let shell = app_handle.shell(); let output = tauri::async_runtime::block_on(async move { shell .command("echo") .args(["Hello from Rust!"]) .output() .await .unwrap() }); if output.status.success() { println!("Result: {:?}", String::from_utf8(output.stdout)); } else { println!("Exit with code: {}", output.status.code().unwrap()); }

Shell plugin default permissions blocked

By default, all potentially dangerous shell plugin commands and scopes are blocked and cannot be accessed. Permissions must be explicitly enabled in the capabilities configuration.

Shell plugin purpose

The shell plugin allows you to access the system shell and spawn child processes.

Shell plugin automatic setup command

To install the shell plugin automatically, run one of: npm run tauri add shell, yarn run tauri add shell, pnpm tauri add shell, deno task tauri add shell, bun tauri add shell, or cargo tauri add shell.

Shell plugin manual setup with Cargo

To manually add the shell plugin, run 'cargo add tauri-plugin-shell' in the src-tauri folder.

Shell plugin Rust initialization

To initialize the shell plugin in Rust, add .plugin(tauri_plugin_shell::init()) to the tauri::Builder::default() chain in lib.rs.

Shell plugin JavaScript usage example

Example JavaScript code showing how to use the shell plugin: import { Command } from '@tauri-apps/plugin-shell'; let result = await Command.create('exec-sh', [ '-c', "echo 'Hello World!'", ]).execute(); console.log(result);

Shell plugin JavaScript installation

To install JavaScript bindings for the shell plugin, run one of: npm install @tauri-apps/plugin-shell, yarn add @tauri-apps/plugin-shell, pnpm add @tauri-apps/plugin-shell, deno add npm:@tauri-apps/plugin-shell, or bun add @tauri-apps/plugin-shell.

Shell plugin allow-execute permission example

Example capability configuration to enable the shell:allow-execute permission for executing the 'sh -c' command with regex validated arguments: { "identifier": "shell:allow-execute", "allow": [ { "name": "exec-sh", "cmd": "sh", "args": [ "-c", { "validator": "\\S+" } ], "sidecar": false } ] }

Single Instance plugin installation via automatic setup

The Single Instance plugin can be installed automatically using package manager commands: npm run tauri add single-instance, yarn run tauri add single-instance, pnpm tauri add single-instance, deno task tauri add single-instance, bun tauri add single-instance, or cargo tauri add single-instance.

Single Instance plugin purpose

The Single Instance plugin ensures that only one instance of a Tauri app is running at a time.

Single Instance plugin manual installation

To manually install the Single Instance plugin, run 'cargo add tauri-plugin-single-instance --target cfg(any(target_os = "macos", windows, target_os = "linux"))' in the src-tauri folder, then modify lib.rs to initialize the plugin with app.handle().plugin(tauri_plugin_single_instance::init(|app, args, cwd| {})).

Single Instance plugin must be registered first

The Single Instance plugin must be the first plugin to be registered to work well, ensuring that it runs before other plugins can interfere.

Single Instance init() closure parameters

The init() method takes a closure with three arguments: app (the AppHandle of the application), args (the list of arguments passed by the user to initiate the new instance), and cwd (the Current Working Directory from which the new application instance was launched). The closure is invoked when a new app instance was started but closed by the plugin.

Single Instance default behavior

By default, when a new instance is initiated while the application is already running, no action is taken.

Single Instance focus new instance example

To focus the window of the running instance when a user tries to open a new instance, use this code: use tauri::{AppHandle, Manager}; let mut builder = tauri::Builder::default(); #[cfg(desktop)] { builder = builder.plugin(tauri_plugin_single_instance::init(|app, args, cwd| { let _ = app.get_webview_window("main").expect("no main window").set_focus(); })); } builder.run(tauri::generate_context!()).expect("error while running tauri application");

Single Instance on Linux uses DBus

On Linux, the Single Instance plugin uses DBus to ensure only one instance is running. The first instance publishes a service to DBus. Following instances try to publish the same service and, if it is already published, send a request to notify the first instance and exit.

Single Instance plugin service naming convention

The Single Instance plugin publishes a service named org.{id}.SingleInstance, where {id} is the identifier from tauri.conf.json with dots (.) and dashes (-) replaced by underscores (_). For example, identifier net.mydomain.MyApp becomes org.net_mydomain_MyApp.SingleInstance.

Single Instance snap configuration

For snap packages, declare a plug and a slot for the single instance service in snapcraft.yml with interface: dbus, bus: session, and the service name org.{id}.SingleInstance. Apply both the plug and slot to the app declaration to allow DBus communication.

Single Instance flatpak configuration

For flatpak packages, declare finish-args in the manifest file with --talk-name=org.{id}.SingleInstance and --own-name=org.{id}.SingleInstance to allow DBus service communication.

Single Instance plugin permissions

The Single Instance plugin currently does not have JavaScript APIs, so capabilities do not need to be configured to use it.

Stronghold JavaScript API example

Example of using the Stronghold plugin from JavaScript: ```javascript import { Client, Stronghold } from '@tauri-apps/plugin-stronghold'; import { appDataDir } from '@tauri-apps/api/path'; const initStronghold = async () => { const vaultPath = `${await appDataDir()}/vault.hold`; const vaultPassword = 'vault password'; const stronghold = await Stronghold.load(vaultPath, vaultPassword); let client; const clientName = 'name your client'; try { client = await stronghold.loadClient(clientName); } catch { client = await stronghold.createClient(clientName); } return { stronghold, client }; }; async function insertRecord(store, key, value) { const data = Array.from(new TextEncoder().encode(value)); await store.insert(key, data); } async function getRecord(store, key) { const data = await store.get(key); return new TextDecoder().decode(new Uint8Array(data)); } const { stronghold, client } = await initStronghold(); const store = client.getStore(); const key = 'my_key'; await insertRecord(store, key, 'secret value'); const value = await getRecord(store, key); console.log(value); // 'secret value' await stronghold.save(); await store.remove(key); ```

Stronghold permission setup

By default all potentially dangerous plugin commands and scopes are blocked. To enable Stronghold, add the permission 'stronghold:default' to the permissions array in src-tauri/capabilities/default.json.

Stronghold JavaScript global access

When using 'withGlobalTauri': true configuration, the Stronghold plugin is available at window.__TAURI__.stronghold with Client and Stronghold exports, and paths are available at window.__TAURI__.path with appDataDir export.

Stronghold plugin purpose

The Stronghold plugin is used to store secrets and keys using the IOTA Stronghold secret management engine, which provides an encrypted, secure database.

Stronghold plugin automatic installation

The Stronghold plugin can be installed automatically using package manager commands: npm run tauri add stronghold, yarn run tauri add stronghold, pnpm tauri add stronghold, bun tauri add stronghold, deno task tauri add stronghold, or cargo tauri add stronghold.

Stronghold plugin manual installation steps

To manually install the Stronghold plugin: (1) Run 'cargo add tauri-plugin-stronghold' in the src-tauri folder. (2) Modify lib.rs to initialize the plugin with .plugin(tauri_plugin_stronghold::Builder::new(|password| {}).build()). (3) Install JavaScript bindings using npm install @tauri-apps/plugin-stronghold, yarn add @tauri-apps/plugin-stronghold, pnpm add @tauri-apps/plugin-stronghold, deno add npm:@tauri-apps/plugin-stronghold, or bun add @tauri-apps/plugin-stronghold.

Stronghold scrypt profile optimization

Due to an upstream bug, it is recommended to add [profile.dev.package.scrypt] with opt-level = 3 to the Cargo.toml file when using the Stronghold plugin.

Stronghold password hash requirement

The Stronghold plugin must be initialized with a password hash function that takes a password string and returns exactly 32 bytes. This is a Stronghold requirement.

Stronghold argon2 initialization example

The Stronghold plugin offers a default hash function using the argon2 algorithm. Example initialization in src-tauri/src/lib.rs: ```rust use tauri::Manager; pub fn run() { tauri::Builder::default() .setup(|app| { let salt_path = app .path() .app_local_data_dir() .expect("could not resolve app local data path") .join("salt.txt"); app.handle().plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?; Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application"); } ```

Stronghold custom hash function initialization

You can provide a custom hash algorithm using tauri_plugin_stronghold::Builder::new with a closure that implements your hash algorithm. Example using rust-argon2 crate: ```rust pub fn run() { tauri::Builder::default() .plugin( tauri_plugin_stronghold::Builder::new(|password| { use argon2::{hash_raw, Config, Variant, Version}; let config = Config { lanes: 4, mem_cost: 10_000, time_cost: 10, variant: Variant::Argon2id, version: Version::Version13, ..Default::default() }; let salt = "your-salt".as_bytes(); let key = hash_raw(password.as_ref(), salt, &config).expect("failed to hash password"); key.to_vec() }) .build(), ) .run(tauri::generate_context!()) .expect("error while running tauri application"); } ```

Upload plugin initialization in lib.rs

To initialize the upload plugin in Rust, add `.plugin(tauri_plugin_upload::init())` to the `tauri::Builder::default()` chain in the `run()` function in `src-tauri/src/lib.rs`.

Upload plugin automatic setup

To automatically set up the upload plugin, use the command `npm run tauri add upload`, `yarn run tauri add upload`, `pnpm tauri add upload`, `deno task tauri add upload`, `bun tauri add upload`, or `cargo tauri add upload` depending on your package manager.

Upload plugin description

The upload plugin provides functionality to upload files from disk to a remote server over HTTP and download files from a remote HTTP server to disk.

Upload plugin setup with Cargo

To set up the upload plugin manually in a Rust Tauri project, run `cargo add tauri-plugin-upload` in the `src-tauri` folder to add the plugin dependency to `Cargo.toml`.

Give your agent this brain