tauri-plugin-clipboard-next-api
v0.2.4
Published
Tauri 2 clipboard plugin - read/write/listen to clipboard (text/rtf/html/image/files) across Windows, macOS, Linux and iOS.
Maintainers
Readme
tauri-plugin-clipboard-next
Tauri 2 剪贴板插件:在 Windows/macOS/Linux/iOS 上读取/写入/监听剪贴板(纯文本/富文本/HTML/图片/文件)。
功能支持
- 纯文本
- Html
- 富文本
- 图片(
PNG格式) - 文件(
file-uri-list格式) - 监听剪贴板变化
平台支持
| 平台 | 支持情况 | |----------|------| | Windows | ✅ | | macOS | ✅ | | Linux | ✅ | | iOS(测试版) | ✅ | | Android | 🚧 |
安装
cargo add tauri-plugin-clipboard-next您可以使用您喜欢的 JavaScript 包管理器安装 JavaScript Guest 绑定:
pnpm add tauri-plugin-clipboard-next-api使用方法
src-tauri/src/lib.rs
pub fn run() {
tauri::Builder::default()
+ .plugin(tauri_plugin_clipboard_next::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}src-tauri/capabilities/default.json
{
...
"permissions": [
...
+ "clipboard-next:default"
]
}之后,所有插件的 API 都可以通过 JavaScript guest 绑定使用:
import { startWatch, onClipboardChange } from 'tauri-plugin-clipboard-next-api';
await startWatch();
const unlisten = await onClipboardChange((clipboard) => {
console.log('Clipboard changed:', clipboard);
});
// 稍后,停止监听
unlisten();方法
| 方法 | 描述 |
|---------------------|--------------------------------------------------|
| startWatch | Start listening for clipboard changes |
| stopWatch | Stop listening for clipboard changes |
| hasText | Check if the clipboard contains plain text |
| hasRtf | Check if the clipboard contains rich text |
| hasHtml | Check if the clipboard contains html |
| hasImage | Check if the clipboard contains an image |
| hasFiles | Check if the clipboard contains files |
| readText | Read plain text from the clipboard |
| readRtf | Read rich text from the clipboard |
| readHtml | Read html from the clipboard |
| readImage | Read image from the clipboard |
| readFiles | Read file paths from the clipboard |
| writeText | Write plain text to the clipboard |
| writeRtf | Write rich text to the clipboard |
| writeHtml | Write html content to the clipboard |
| writeImage | Write an image to the clipboard from a file path |
| writeFiles | Write file paths to the clipboard |
| clear | Clear the clipboard contents |
| getFilePath | Get the file path for clipboard operations |
| readClipboard | Read all available content from the clipboard |
| onClipboardChange | Listen for clipboard changes |
示例
git clone https://github.com/zhoushi1/tauri-plugin-clipboard-next.gitpnpm install
pnpm build
cd examples/tauri-app
pnpm install
pnpm tauri dev致谢
- 特别感谢 clipboard-rs crate,它为这个 Tauri 2 插件提供了可靠的跨平台剪贴板操作能力(支持纯文本、富文本、HTML、图片和文件)。
