Skip to main content

Crate tauri_plugin_vnidrop_share

Crate tauri_plugin_vnidrop_share 

Source
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§

CanShareResult
The result type for the can_share command.
ShareOptions
Defines the content and options for a native sharing dialog.
SharedFile
Represents a file to be shared, including its content, name, and MIME type.

Enums§

Error
Defines the custom error types for the plugin.

Traits§

ShareExt
Extensions to tauri::App, tauri::AppHandle and tauri::Window to access the share APIs.

Functions§

init
Initializes the plugin.

Type Aliases§

Result