@tauri-apps/plugin-clipboard-manager
读取和写入系统剪贴板。
function clear(): Promise<void>
清空剪贴板。
平台特定
- Android:仅在 SDK 28+ 上受支持。对于早期版本,我们会在剪贴板写入空字符串。
Promise
<void
>
import { clear } from '@tauri-apps/plugin-clipboard-manager';await clear();
2.0.0
function readImage(): Promise<Image>
将剪贴板内容作为 Uint8Array 图像获取。
平台特定
- Android / iOS:不支持。
Promise
<Image
>
import { readImage } from '@tauri-apps/plugin-clipboard-manager';
const clipboardImage = await readImage();const blob = new Blob([await clipboardImage.rgba()], { type: 'image' })const url = URL.createObjectURL(blob)
2.0.0
function readText(): Promise<string>
以纯文本形式获取剪贴板内容。
Promise
<string
>
import { readText } from '@tauri-apps/plugin-clipboard-manager';const clipboardText = await readText();
2.0.0
function writeHtml(html, altText?): Promise<void>
- 将 HTML 写入剪贴板,或回退写入所提供的纯文本。
平台特定
- Android / iOS:不支持。
参数 | 类型 |
---|---|
html | 字符串 |
altText ? | 字符串 |
Promise
<void
>
表示操作成功或失败的 Promise。
import { writeHtml } from '@tauri-apps/plugin-clipboard-manager';await writeHtml('<h1>Tauri is awesome!</h1>', 'plaintext');// The following will write "<h1>Tauri is awesome</h1>" as plain textawait writeHtml('<h1>Tauri is awesome!</h1>', '<h1>Tauri is awesome</h1>');// we can read html data only as a string so there's just readText(), no readHtml()assert(await readText(), '<h1>Tauri is awesome!</h1>');
2.0.0
function writeImage(image): Promise<void>
将图像缓冲区写入剪贴板。
平台特定
- Android / iOS:不支持。
参数 | 类型 |
---|---|
image | | string | number [] | ArrayBuffer | Uint8Array | Image |
Promise
<void
>
表示操作成功或失败的 Promise。
import { writeImage } from '@tauri-apps/plugin-clipboard-manager';const buffer = [ // A red pixel 255, 0, 0, 255,
// A green pixel 0, 255, 0, 255,];await writeImage(buffer);
2.0.0
function writeText(text, opts?): Promise<void>
将纯文本写入剪贴板。
参数 | 类型 |
---|---|
文本 | 字符串 |
选项 ? | 对象 |
opts.label ? | 字符串 |
Promise
<void
>
表示操作成功或失败的 Promise。
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager';await writeText('Tauri is awesome!');assert(await readText(), 'Tauri is awesome!');
2.0.0
© 2025 Tauri 贡献者。CC-BY / MIT