Expand description
§tauri-plugin-vnidrop-share
A Tauri plugin to share content using the native sharing dialog on Windows, macOS, and mobile platforms.
On desktop, the plugin handles sharing text, URLs, and files. For files, it manages their lifecycle by creating temporary files from Base64 content and cleaning them up once the share dialog is closed or the application exits.
§Installation
# Cargo.toml
[dependencies]
tauri-plugin-vnidrop-share = { git = "[https://github.com/vnidrop/plugin-share](https://github.com/vnidrop/plugin-share)" }§Usage
§Rust
You need to initialize the plugin in your main.rs or lib.rs to register the commands and set up state management.
// src/main.rs
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_vnidrop_share::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}§Frontend (JavaScript/TypeScript)
The plugin provides a JavaScript API to call the commands.
import { share, canShare } from '@vnidrop/tauri-plugin-share';
// Check if sharing is available
const canShareResult = await canShare();
console.log(`Can share on this platform: ${canShareResult}`);
// Share text and a URL
if (canShareResult) {
await share({
title: 'Check this out!',
text: 'I found this cool project built with Tauri.',
url: '[https://tauri.app](https://tauri.app)',
});
}
// Share a file from Base64 content
// The file will be created as a temporary file and cleaned up automatically.
const fileContent = '...'; // Your Base64-encoded file data
const blob = new Blob([fileContent], { type: 'text/plain' });
await share({
files: [new File([blob], 'document.txt')],
});Structs§
- CanShare
Result - The result type for the
can_sharecommand. - Share
Options - Defines the content and options for a native sharing dialog.
- Shared
File - Represents a file to be shared, including its content, name, and MIME type.
Enums§
- Error
- Defines the custom error types for the plugin.
Traits§
- Share
Ext - Extensions to
tauri::App,tauri::AppHandleandtauri::Windowto access the share APIs.
Functions§
- init
- Initializes the plugin.