剪贴板
使用剪贴板插件读取和写入系统剪贴板。
🌐 Read and write to the system clipboard using the clipboard plugin.
🌐 Supported Platforms
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | | Only plain-text content support |
| ios | | Only plain-text content support |
🌐 Setup
安装剪贴板插件即可开始使用。
🌐 Install the clipboard plugin to get started.
使用项目的包管理器添加依赖:
npm run tauri add clipboard-manageryarn run tauri add clipboard-managerpnpm tauri add clipboard-managerdeno task tauri add clipboard-managerbun tauri add clipboard-managercargo tauri add clipboard-manager-
在
src-tauri文件夹中运行以下命令,将插件添加到Cargo.toml中的项目依赖:cargo add tauri-plugin-clipboard-manager -
修改
lib.rs以初始化插件:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_clipboard_manager::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
如果你想在 JavaScript 中管理剪贴板,那么也请安装这个 npm 包:
npm install @tauri-apps/plugin-clipboard-manageryarn add @tauri-apps/plugin-clipboard-managerpnpm add @tauri-apps/plugin-clipboard-managerdeno add npm:@tauri-apps/plugin-clipboard-managerbun add @tauri-apps/plugin-clipboard-manager
🌐 Usage
剪贴板插件在 JavaScript 和 Rust 中均可用。
🌐 The clipboard plugin is available in both JavaScript and Rust.
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager';// when using `"withGlobalTauri": true`, you may use// const { writeText, readText } = window.__TAURI__.clipboardManager;
// Write content to clipboardawait writeText('Tauri is awesome!');
// Read content from clipboardconst content = await readText();console.log(content);// Prints "Tauri is awesome!" to the consoleuse tauri_plugin_clipboard_manager::ClipboardExt;
app.clipboard().write_text("Tauri is awesome!".to_string()).unwrap();
// Read content from clipboardlet content = app.clipboard().read_text();println!("{:?}", content.unwrap());// Prints "Tauri is awesome!" to the terminalDefault Permission
No features are enabled by default, as we believe the clipboard can be inherently dangerous and it is application specific if read and/or write access is needed.
Clipboard interaction needs to be explicitly enabled.
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the clear command without any pre-configured scope. |
|
|
Denies the clear command without any pre-configured scope. |
|
|
Enables the read_image command without any pre-configured scope. |
|
|
Denies the read_image command without any pre-configured scope. |
|
|
Enables the read_text command without any pre-configured scope. |
|
|
Denies the read_text command without any pre-configured scope. |
|
|
Enables the write_html command without any pre-configured scope. |
|
|
Denies the write_html command without any pre-configured scope. |
|
|
Enables the write_image command without any pre-configured scope. |
|
|
Denies the write_image command without any pre-configured scope. |
|
|
Enables the write_text command without any pre-configured scope. |
|
|
Denies the write_text command without any pre-configured scope. |
Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站