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 1 of 4.

Plugin documentation structure: official features, community plugins, community integrations

The plugin documentation is organized into three main sections: Official Features, Community Plugins (found in Awesome Tauri's plugins-no-official section), and Community Integrations (found in Awesome Tauri's integrations section). The documentation includes a search and filter functionality to find features or community resources, and a compatibility table showing which platforms are supported by each official plugin.

Tauri extensibility: official features, community plugins, and recipes

Tauri comes with extensibility in mind. The plugin documentation covers official features (built-in Tauri features and functionality), community resources (more plugins and recipes built by the Tauri community, which can be contributed to Awesome Tauri), and a support table showing which platforms are supported by each official plugin.

Default log format

The log plugin formats each log record as: DATE[TARGET][LEVEL] MESSAGE.

Folder target for custom log directory

The Folder target writes logs to a custom filesystem location. Configuration: 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(). The default file_name is the application name.

Log plugin capabilities configuration

Add log plugin permissions to src-tauri/capabilities/default.json in the permissions array. Example: { "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": ["log:default"] }.

Log plugin targets configuration

The log plugin builder has a targets() function to configure log destinations. By default, logs go to stdout and to a file in the application logs directory. Call clear_targets() to use only custom log targets.

Logging from JavaScript

To log from JavaScript, import the desired function (warn, debug, trace, info, or error) from @tauri-apps/plugin-log and call it with a message string. Example: trace('Trace'), info('Info'), error('Error').

Forward console messages to log plugin

To automatically forward console.log, console.debug, console.info, console.warn, and console.error to the log plugin, override the console methods to call both the original method and the corresponding logger function.

Log file rotation strategy

Configure automatic log file rotation when the size limit is reached using: tauri_plugin_log::Builder::new().rotation_strategy(tauri_plugin_log::RotationStrategy::KeepAll).build(). This prevents the previous log file from being discarded.

Log plugin installation commands

The log plugin can be installed automatically using: npm run tauri add log, yarn run tauri add log, pnpm tauri add log, deno task tauri add log, bun tauri add log, or cargo tauri add log. Alternatively, manually run cargo add tauri-plugin-log in the src-tauri folder, then modify lib.rs to initialize the plugin with tauri::Builder::default().plugin(tauri_plugin_log::Builder::new().build()), and install the JavaScript bindings using npm install @tauri-apps/plugin-log, yarn add @tauri-apps/plugin-log, pnpm add @tauri-apps/plugin-log, deno add npm:@tauri-apps/plugin-log, or bun add @tauri-apps/plugin-log.

Webview target for logging

To view Rust logs in the webview console, enable the Webview target in the plugin builder and call attachConsole() in the frontend. The builder configuration is: tauri_plugin_log::Builder::new().target(tauri_plugin_log::Target::new(tauri_plugin_log::TargetKind::Webview)).build(). Frontend code: const detach = await attachConsole(); call detach() to stop printing logs to console.

Custom log format

Provide a custom format function: tauri_plugin_log::Builder::new().format(|out, message, record| { out.finish(format_args!("[{} {}] {}", record.level(), record.target(), message)) }).build(). The format function receives the output writer, formatted message, and log record.

Target filter for log exclusion

Use a filter function to discard unwanted logs by checking metadata: tauri_plugin_log::Builder::new().filter(|metadata| metadata.target() != "hyper").build(). The filter receives metadata and should return true to keep the log.

Stdout target for logging

To forward logs to the terminal, enable the Stdout target: tauri_plugin_log::Builder::new().target(tauri_plugin_log::Target::new(tauri_plugin_log::TargetKind::Stdout)).build(). This target is enabled by default.

Different log formats per target

Call clear_format() on the builder to remove the default formatter, then specify a custom format method on individual Target objects. Each target can have its own format function via .format(move |out, message, record| { /* custom formatter */ }).

LogDir target for file logging

The LogDir target writes logs to a file in the recommended log directory. Configuration: tauri_plugin_log::Builder::new().target(tauri_plugin_log::Target::new(tauri_plugin_log::TargetKind::LogDir { file_name: Some("logs".to_string()) })).build(). Log locations by platform: Linux uses $XDG_DATA_HOME/{bundleIdentifier}/logs or $HOME/.local/share/{bundleIdentifier}/logs (example: /home/alice/.local/share/com.tauri.dev/logs), macOS uses {homeDir}/Library/Logs/{bundleIdentifier} (example: /Users/Alice/Library/Logs/com.tauri.dev), Windows uses {FOLDERID_LocalAppData}/{bundleIdentifier}/logs (example: C:\Users\Alice\AppData\Local\com.tauri.dev\logs).

Log plugin default permissions

By default, all log plugin commands are blocked. Define permissions in the capabilities configuration file using "log:default" to enable access.

Log timezone configuration

By default, the log plugin uses UTC timezone for dates. Change to local timezone: tauri_plugin_log::Builder::new().timezone_strategy(tauri_plugin_log::TimezoneStrategy::UseLocal).build().

Maximum log level filtering

To set a maximum log level, use: tauri_plugin_log::Builder::new().level(log::LevelFilter::Info).build(). This discards logs below the specified level. Also set different levels for specific modules: .level_for("my_crate_name::commands", log::LevelFilter::Trace).

Log plugin JavaScript API functions

The log plugin exports the following JavaScript functions from @tauri-apps/plugin-log: warn, debug, trace, info, error, attachConsole, and attachLogger. These are available for import or via window.__TAURI__.log when using withGlobalTauri: true.

Logging from Rust

To log from Rust, use the log crate macros: log::error!(), log::info!(), log::debug!(), log::trace!(), and log::warn!(). The log crate version 0.4 must be added to Cargo.toml as a dependency.

Log file size configuration

By default, the log file is discarded when reaching maximum size. Configure the maximum file size using: tauri_plugin_log::Builder::new().max_file_size(50_000 /* bytes */).build(). Size is specified in bytes.

notification plugin security considerations

The notification plugin has no known security considerations aside from normal sanitization procedures of user input.

sendNotification with channelId JavaScript example

JavaScript example for sending a notification to a specific channel: import { sendNotification } from '@tauri-apps/plugin-notification'; sendNotification({ title: 'New Message', body: 'You have a new message', channelId: 'messages', });

registerActionTypes notification API

Register action types using registerActionTypes() with an array of action type objects. Each object has: id (string, unique identifier), and actions (array of action objects). Each action object has: id (string, unique identifier), title (string, display text), requiresAuthentication (boolean, optional), foreground (boolean, optional, brings app to foreground when triggered), destructive (boolean, optional, shows red on iOS), input (boolean, optional, enables text input), inputButtonTitle (string, optional, text for submit button), inputPlaceholder (string, optional, placeholder text).

createChannel JavaScript example

JavaScript example for creating a notification channel: import { createChannel, Importance, Visibility, } from '@tauri-apps/plugin-notification'; await createChannel({ id: 'messages', name: 'Messages', description: 'Notifications for new messages', importance: Importance.High, visibility: Visibility.Private, lights: true, lightColor: '#ff0000', vibration: true, sound: 'notification_sound', });

createChannel notification API

Create notification channels using createChannel() with a channel object containing: id (string, unique identifier), name (string, display name), description (string, purpose description), importance (enum: None, Min, Low, Default, High, priority level), visibility (enum: Secret, Private, Public, privacy setting), lights (boolean, enable notification LED on Android), lightColor (string, LED color on Android), vibration (boolean, enable vibrations), sound (string, custom sound filename).

sendNotification with channelId

Send a notification to a specific channel using sendNotification() with a channelId property in the notification object. Channels must be created before sending notifications that reference them, otherwise invalid channel IDs will prevent notifications from displaying.

sendNotification with attachments JavaScript example

JavaScript example for sending a notification with attachments: import { sendNotification } from '@tauri-apps/plugin-notification'; sendNotification({ title: 'New Image', body: 'Check out this picture', attachments: [ { id: 'image-1', url: 'asset:///notification-image.jpg', }, ], });

onAction JavaScript example

JavaScript example for listening to notification actions: import { onAction } from '@tauri-apps/plugin-notification'; await onAction((notification) => { console.log('Action performed:', notification); });

onAction notification listener

Listen to user interactions with notification actions using onAction() which accepts a callback that receives the notification object when an action is performed.

registerActionTypes JavaScript example

JavaScript example for registering action types: import { registerActionTypes } from '@tauri-apps/plugin-notification'; await registerActionTypes([ { id: 'messages', actions: [ { id: 'reply', title: 'Reply', input: true, inputButtonTitle: 'Send', inputPlaceholder: 'Type your reply...', }, { id: 'mark-read', title: 'Mark as Read', foreground: false, }, ], }, ]);

removeChannel JavaScript example

JavaScript example for removing a notification channel: import { removeChannel } from '@tauri-apps/plugin-notification'; await removeChannel('messages');

notification actions mobile only

The Actions API for adding interactive buttons and inputs to notifications is only available on mobile platforms.

send notification Rust example

Rust example for sending a notification: tauri::Builder::default() .plugin(tauri_plugin_notification::init()) .setup(|app| { use tauri_plugin_notification::NotificationExt; app.notification() .builder() .title("Tauri") .body("Tauri is awesome") .show() .unwrap(); Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");

send notification JavaScript example

JavaScript example for sending a notification: import { isPermissionGranted, requestPermission, sendNotification, } from '@tauri-apps/plugin-notification'; let permissionGranted = await isPermissionGranted(); if (!permissionGranted) { const permission = await requestPermission(); permissionGranted = permission === 'granted'; } if (permissionGranted) { sendNotification({ title: 'Tauri', body: 'Tauri is awesome!' }); } Alternatively, when using withGlobalTauri: true, use window.__TAURI__.notification with the same functions.

notification plugin manual setup lib.rs initialization

To manually initialize the notification plugin in Rust, modify src-tauri/src/lib.rs to include .plugin(tauri_plugin_notification::init()) in the Builder chain, after tauri::Builder::default().

notification plugin manual setup Cargo.toml

To manually set up the notification plugin in Rust, run 'cargo add tauri-plugin-notification' in the src-tauri folder to add the plugin to Cargo.toml dependencies.

notification plugin setup automatic installation

The notification plugin can be installed automatically using package managers with the command: npm run tauri add notification (npm), yarn run tauri add notification (yarn), pnpm tauri add notification (pnpm), bun tauri add notification (bun), deno task tauri add notification (deno), or cargo tauri add notification (cargo).

channels JavaScript example

JavaScript example for listing existing notification channels: import { channels } from '@tauri-apps/plugin-notification'; const existingChannels = await channels();

sendNotification attachments API

Notifications support attachments with an attachments array property. Each attachment object has: id (string, unique identifier), url (string, content URL using asset:// or file:// protocol). Attachment support varies by platform.

notification plugin JavaScript npm installation

To use notifications in JavaScript, install the npm package using: npm install @tauri-apps/plugin-notification (npm), yarn add @tauri-apps/plugin-notification (yarn), pnpm add @tauri-apps/plugin-notification (pnpm), deno add npm:@tauri-apps/plugin-notification (deno), or bun add @tauri-apps/plugin-notification (bun).

removeChannel notification API

Remove a notification channel using removeChannel() which takes a channel id (string) as parameter.

channels list existing notification channels

List existing notification channels using channels() which returns an array of channel objects.

Opener plugin setup - manual Rust installation

For manual setup: (1) Run 'cargo add tauri-plugin-opener' in the src-tauri folder. (2) Modify lib.rs to add .plugin(tauri_plugin_opener::init()) to the tauri::Builder::default() chain. (3) Install JavaScript bindings with npm install @tauri-apps/plugin-opener (or yarn add, pnpm add, deno add npm:, or bun add).

Opener plugin setup - automatic installation

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

Opener plugin purpose

The opener plugin allows you to open files and URLs in a specified or the default application. It also supports revealing files in the system's file explorer.

Opener permissions default behavior

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

Opener permission - allow-open-url

The 'opener:allow-open-url' permission enables the openUrl() function. Configure in capabilities JSON with 'allow' array containing objects with 'url' property using glob pattern syntax. Example: {"url": "https://tauri.app"} or {"url": "custom:*"}.

Opener permission - allow-open-path

The 'opener:allow-open-path' permission enables the openPath() function. Configure in capabilities JSON with 'allow' array containing objects with 'path' property using glob pattern syntax. Example: {"path": "/path/to/file"} or {"path": "$APPDATA/file"}.

Opener Rust API - open_url

open_url() opens a URL using the default program or specified application. Usage with app (instance of App or AppHandle): app.opener().open_url("https://tauri.app", None::<&str>);. Requires use tauri_plugin_opener::OpenerExt;

Opener Rust API - open_path

open_path() opens a file using the default program or specified application. Usage with app (instance of App or AppHandle): app.opener().open_path("/path/to/file", None::<&str>); or app.opener().open_path("C:/path/to/file", Some("vlc"));. Requires use tauri_plugin_opener::OpenerExt;

Opener JavaScript imports

Import from '@tauri-apps/plugin-opener': import { openPath, openUrl } from '@tauri-apps/plugin-opener';. When using 'withGlobalTauri': true, access via window.__TAURI__.opener.

Opener JavaScript API - openUrl

openUrl() opens a URL using the default program or a specified application. Usage: await openUrl('https://tauri.app').

Opener JavaScript API - openPath

openPath() opens a file using the default program or a specified application. Usage: await openPath('/path/to/file') opens with default program; await openPath('C:/path/to/file', 'vlc') opens with vlc command on Windows.

persisted-scope setup with manual installation

To manually install the persisted-scope plugin, run cargo add tauri-plugin-persisted-scope in the src-tauri folder, then modify lib.rs to include .plugin(tauri_plugin_persisted_scope::init()) in the tauri::Builder::default() chain.

persisted-scope plugin initialization order requirement

The persisted-scope plugin must be registered and initialized after the fs plugin. If the fs plugin is not initialized before persisted-scope, the persisted scope will not work correctly, and a warning message will appear upon launching the app in dev mode.

persisted-scope automatic behavior

After setup, the persisted-scope plugin automatically saves and restores filesystem and asset scopes without requiring additional configuration.

persisted-scope plugin overview

The persisted-scope plugin saves filesystem and asset scopes and restores them when the app is reopened.

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'.

Give your agent this brain