Skip to content

Commit

Permalink
fix: Fix write RTF error, Bump version to v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed Jun 19, 2024
1 parent 37316cf commit cce4abe
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tauri-plugin-clipboard"
license = "MIT"
version = "1.1.0"
version = "1.1.1"
description = "A clipboard plugin for Tauri that supports text, files and image, as well as clipboard update listening."
authors = [ "Huakun" ]
edition = "2021"
Expand Down
54 changes: 50 additions & 4 deletions examples/demo/src/lib/components/read-and-write.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import clipboard from 'tauri-plugin-clipboard-api';
let text = '';
let rtf = '';
let html = '';
let imageBase64 = '';
let imageObjectUrl = '';
Expand Down Expand Up @@ -29,6 +30,23 @@
{#if text}
<pre class="border p-2 rounded-lg">{text}</pre>
{/if}
<button
type="button"
class="btn variant-filled block btn-sm"
on:click={() => {
clipboard
.readRtf()
.then((t) => {
rtf = t;
})
.catch(alert);
}}
>
Read RTF
</button>
{#if rtf}
<pre class="border p-2 rounded-lg">{rtf}</pre>
{/if}

<button
type="button"
Expand Down Expand Up @@ -93,7 +111,28 @@
type="button"
class="btn variant-filled block btn-sm"
on:click={async () => {
clipboard.writeFilesURIs(['file:///Users/hacker/Dev/brain/docs/notes/Analysis/LaunchApp/raycast.md']).catch(alert);
await clipboard.writeRtf(`{\\rtf1\\ansi\\ansicpg1252\\cocoartf2761
\\cocoatextscaling0\\cocoaplatform0{\\fonttbl\\f0\\fswiss\\fcharset0 Arial-BoldMT;\\f1\\froman\\fcharset0 Times-Roman;}
{\\colortbl;\\red255\\green255\\blue255;\\red230\\green0\\blue14;}
{\\*\\expandedcolortbl;;\\cssrgb\\c93213\\c13483\\c4656;}
\\deftab720
\\pard\\pardeftab720\\partightenfactor0
\\f0\\b\\fs48 \\cf2 \\up0 \\nosupersub \\ulnone hello
\\f1\\b0\\fs24 \\cf2 \\
World}`);
}}
>
Write RTF
</button>

<button
type="button"
class="btn variant-filled block btn-sm"
on:click={async () => {
clipboard
.writeFilesURIs(['file:///Users/hacker/Dev/brain/docs/notes/Analysis/LaunchApp/raycast.md'])
.catch(alert);
}}
>
Write Files URIs
Expand All @@ -103,7 +142,9 @@
type="button"
class="btn variant-filled block btn-sm"
on:click={async () => {
clipboard.writeFiles(['/Users/hacker/Dev/brain/docs/notes/Analysis/LaunchApp/raycast.md']).catch(alert);
clipboard
.writeFiles(['/Users/hacker/Dev/brain/docs/notes/Analysis/LaunchApp/raycast.md'])
.catch(alert);
}}
>
Write Files Paths
Expand All @@ -113,7 +154,9 @@
type="button"
class="btn variant-filled block btn-sm"
on:click={async () => {
await clipboard.writeHtml('<h1 style="color:red; font-size:larger;">HTML written by writeHtml</h1>');
await clipboard.writeHtml(
'<h1 style="color:red; font-size:larger;">HTML written by writeHtml</h1>'
);
}}
>
Write HTML
Expand All @@ -123,7 +166,10 @@
type="button"
class="btn variant-filled block btn-sm"
on:click={async () => {
await clipboard.writeHtmlAndText('<h1 style="color:red; font-size:larger;">HTML written by <code>writeHtmlAndText</code></h1>', 'HTML written by writeHtmlAndText');
await clipboard.writeHtmlAndText(
'<h1 style="color:red; font-size:larger;">HTML written by <code>writeHtmlAndText</code></h1>',
'HTML written by writeHtmlAndText'
);
}}
>
Write HTML and Text
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tauri-plugin-clipboard-api",
"version": "1.1.0",
"version": "1.1.1",
"author": "Huakun Shen",
"type": "module",
"description": "",
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ fn write_html_and_text(
}

#[tauri::command]
fn write_rtf(manager: State<'_, ClipboardManager>, rtf_content: String) -> Result<(), String> {
manager.write_rtf(rtf_content)
fn write_rtf(manager: State<'_, ClipboardManager>, rtf: String) -> Result<(), String> {
manager.write_rtf(rtf)
}

/// read image from clipboard and return a base64 string
Expand Down

0 comments on commit cce4abe

Please sign in to comment.