@tauri-apps/plugin-clipboard-manager
读写系统剪贴板。
函数
clear()
function clear(): Promise<void>
清空剪贴板。
特定平台
- Android: 仅支持 SDK 28+。对于旧版本,我们会在剪贴板中写入一个空字符串。
返回值
Promise
<void
>
示例
import { clear } from '@tauri-apps/plugin-clipboard-manager';await clear();
自
2.0.0
readImage()
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.rbga()], { type: 'image' })const url = URL.createObjectURL(blob)
自
2.0.0
readText()
function readText(): Promise<string>
获取剪贴板内容作为纯文本。
返回值
Promise
<string
>
示例
import { readText } from '@tauri-apps/plugin-clipboard-manager';const clipboardText = await readText();
自
2.0.0
writeHtml()
function writeHtml(html, altText?): Promise<void>
- 写入 HTML 或回退到将提供的纯文本写入剪贴板。
特定平台
- Android / iOS: 不支持。
参数
参数 | 类型 |
---|---|
html | string |
altText ? | string |
返回值
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
writeImage()
function writeImage(image): Promise<void>
将图像缓冲区写入剪贴板。
特定平台
- Android / iOS: 不支持。
参数
参数 | 类型 |
---|---|
图像 | | string | number [] | ArrayBuffer | Uint8Array <ArrayBufferLike > | 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
writeText()
function writeText(text, opts?): Promise<void>
将纯文本写入剪贴板。
参数
参数 | 类型 |
---|---|
text | string |
opts ? | object |
opts.label ? | string |
返回值
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