This commit is contained in:
Jonas Kruckenberg 2022-11-17 19:03:46 +01:00
parent e5b7d397f0
commit e638b5c289
12 changed files with 247 additions and 1 deletions

View file

@ -1,3 +1,21 @@
//! Read and write to the system clipboard.
//!
//! The APIs must be added to tauri.allowlist.clipboard in tauri.conf.json:
//! ```json
//! {
//! "tauri": {
//! "allowlist": {
//! "clipboard": {
//! "all": true, // enable all Clipboard APIs
//! "writeText": true,
//! "readText": true
//! }
//! }
//! }
//! }
//! ```
//! It is recommended to allowlist only the APIs you use for optimal bundle size and security.
/// Gets the clipboard content as plain text.
///
/// # Example
@ -7,6 +25,8 @@
///
/// let clipboard_text = read_text().await;
/// ```
///
/// Requires [`allowlist > clipboard > readText`](https://tauri.app/v1/api/config#clipboardallowlistconfig.readtext) to be enabled.
#[inline(always)]
pub async fn read_text() -> crate::Result<String> {
let js_val = inner::readText().await?;
@ -24,6 +44,8 @@ pub async fn read_text() -> crate::Result<String> {
/// write_text("Tauri is awesome!").await;
/// assert_eq!(read_text().await, "Tauri is awesome!");
/// ```
///
/// Requires [`allowlist > clipboard > writeText`](https://tauri.app/v1/api/config#clipboardallowlistconfig.writetext) to be enabled.
#[inline(always)]
pub async fn write_text(text: &str) -> crate::Result<()> {
Ok(inner::writeText(text).await?)