From 83642a354f73fb5416737530133f3a8d9ab9ac71 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Thu, 22 Feb 2024 00:32:26 +0100 Subject: [PATCH 01/17] Implement arboard HTML features (desktop only) and ability to trigger clipboard clear Signed-off-by: TukanDev --- plugins/clipboard-manager/guest-js/index.ts | 59 ++++++++++++++++++++- plugins/clipboard-manager/src/commands.rs | 25 +++++++++ plugins/clipboard-manager/src/desktop.rs | 43 +++++++++++++-- plugins/clipboard-manager/src/lib.rs | 11 +++- plugins/clipboard-manager/src/mobile.rs | 13 +++++ plugins/clipboard-manager/src/models.rs | 2 + 6 files changed, 147 insertions(+), 6 deletions(-) diff --git a/plugins/clipboard-manager/guest-js/index.ts b/plugins/clipboard-manager/guest-js/index.ts index 4a9d10a0ec..cd94540bfd 100644 --- a/plugins/clipboard-manager/guest-js/index.ts +++ b/plugins/clipboard-manager/guest-js/index.ts @@ -11,6 +11,7 @@ import { invoke } from "@tauri-apps/api/core"; type ClipResponse = Record<"plainText", { text: string }>; +type ClipHtmlResponse = Record<"html", { html: string, alt_html: string }>; /** * Writes plain text to the clipboard. @@ -53,4 +54,60 @@ async function readText(): Promise { return kind.plainText.text; } -export { writeText, readText }; +/** + * Writes HTML or fallbacks to write provided plain text to the clipboard. + * @example + * ```typescript + * import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager'; + * await writeHtml('

Tauri is awesome!

', 'plaintext'); + * await writeHtml('

Tauri is awesome!

', '

Tauri is awesome

'); // Will write "

Tauri is awesome

" as plain text + * assert(await readHtml(), '

Tauri is awesome!

'); + * ``` + * + * @returns A promise indicating the success or failure of the operation. + * + * @since 2.0.0 + */ +async function writeHtml( + html: string, + alt_html: string +): Promise { + return invoke("plugin:clipboard-manager|write_html", { + data: { + html: { + html, + alt_html + }, + }, + }); +} + +/** + * Gets the clipboard content as HTML text. + * @example + * ```typescript + * import { readHtml } from '@tauri-apps/plugin-clipboard-manager'; + * const clipboardHtml = await readHtml(); + * ``` + * @since 2.0.0 + */ +async function readHtml(): Promise { + const kind: ClipHtmlResponse = await invoke("plugin:clipboard-manager|read_html"); + return kind.html +} + +/** + * Gets the clipboard content as HTML text. + * @example + * ```typescript + * import { readHtml } from '@tauri-apps/plugin-clipboard-manager'; + * const clipboardHtml = await readHtml(); + * ``` + * @since 2.0.0 + */ +async function clear(): Promise { + await invoke("plugin:clipboard-manager|clear"); + return; +} + +export { writeText, readText, writeHtml, readHtml, clear }; diff --git a/plugins/clipboard-manager/src/commands.rs b/plugins/clipboard-manager/src/commands.rs index eec868a84f..49c459a3ed 100644 --- a/plugins/clipboard-manager/src/commands.rs +++ b/plugins/clipboard-manager/src/commands.rs @@ -22,3 +22,28 @@ pub(crate) async fn read( ) -> Result { clipboard.read() } + +#[command] +pub(crate) async fn write_html( + _app: AppHandle, + clipboard: State<'_, Clipboard>, + data: ClipKind, +) -> Result<()> { + clipboard.write_html(data) +} + +#[command] +pub(crate) async fn read_html( + _app: AppHandle, + clipboard: State<'_, Clipboard>, +) -> Result { + clipboard.read() +} + +#[command] +pub(crate) async fn clear( + _app: AppHandle, + clipboard: State<'_, Clipboard>, +) -> Result<()> { + clipboard.clear() +} diff --git a/plugins/clipboard-manager/src/desktop.rs b/plugins/clipboard-manager/src/desktop.rs index 555321dc18..4821abfac5 100644 --- a/plugins/clipboard-manager/src/desktop.rs +++ b/plugins/clipboard-manager/src/desktop.rs @@ -28,10 +28,14 @@ pub struct Clipboard { impl Clipboard { pub fn write(&self, kind: ClipKind) -> crate::Result<()> { - let ClipKind::PlainText { text, .. } = kind; - match &self.clipboard { - Ok(clipboard) => clipboard.lock().unwrap().set_text(text).map_err(Into::into), - Err(e) => Err(crate::Error::Clipboard(e.to_string())), + match kind { + ClipKind::PlainText { text, .. } => { + match &self.clipboard { + Ok(clipboard) => clipboard.lock().unwrap().set_text(text).map_err(Into::into), + Err(e) => Err(crate::Error::Clipboard(e.to_string())), + } + } + _ => Err(crate::Error::Clipboard("Invalid clip kind!".to_string())), } } @@ -44,4 +48,35 @@ impl Clipboard { Err(e) => Err(crate::Error::Clipboard(e.to_string())), } } + + pub fn write_html(&self, kind: ClipKind) -> crate::Result<()> { + match kind { + ClipKind::Html { html, alt_html, .. } => match &self.clipboard { + Ok(clipboard) => clipboard.lock().unwrap().set_html(html, alt_html).map_err(Into::into), + Err(e) => Err(crate::Error::Clipboard(e.to_string())), + } + _ => Err(crate::Error::Clipboard("Invalid clip kind!".to_string())), + } + } + + pub fn read_html(&self) -> crate::Result { + match &self.clipboard { + Ok(clipboard) => { + let html = clipboard.lock().unwrap().get_text()?; + // arboard does not have read_html() as its just text, therefor unable to populate alt_html in this case + Ok(ClipboardContents::Html { html, alt_html: None }) + } + Err(e) => Err(crate::Error::Clipboard(e.to_string())), + } + } + + pub fn clear(&self) -> crate::Result<()> { + match &self.clipboard { + Ok(clipboard) => { + clipboard.lock().unwrap().clear().unwrap(); + Ok(()) + } + Err(e) => Err(crate::Error::Clipboard(e.to_string())), + } + } } diff --git a/plugins/clipboard-manager/src/lib.rs b/plugins/clipboard-manager/src/lib.rs index 2b7934ab30..3f830e161b 100644 --- a/plugins/clipboard-manager/src/lib.rs +++ b/plugins/clipboard-manager/src/lib.rs @@ -49,7 +49,16 @@ impl> crate::ClipboardExt for T { pub fn init() -> TauriPlugin { Builder::new("clipboard-manager") .js_init_script(include_str!("api-iife.js").to_string()) - .invoke_handler(tauri::generate_handler![commands::write, commands::read]) + .invoke_handler(tauri::generate_handler![ + commands::write, + commands::read, + #[cfg(desktop)] + commands::write_html, + #[cfg(desktop)] + commands::read_html, + #[cfg(desktop)] + commands::clear + ]) .setup(|app, api| { #[cfg(mobile)] let clipboard = mobile::init(app, api)?; diff --git a/plugins/clipboard-manager/src/mobile.rs b/plugins/clipboard-manager/src/mobile.rs index 0796471126..970a95975d 100644 --- a/plugins/clipboard-manager/src/mobile.rs +++ b/plugins/clipboard-manager/src/mobile.rs @@ -39,4 +39,17 @@ impl Clipboard { pub fn read(&self) -> crate::Result { self.0.run_mobile_plugin("read", ()).map_err(Into::into) } + + // Treat HTML as unsupported on mobile until tested + pub fn write_html(&self) -> crate::Result { + Err(crate::Error::Clipboard( + "Unsupported on this platform".to_string(), + )) + } + + pub fn read_html(&self) -> crate::Result { + Err(crate::Error::Clipboard( + "Unsupported on this platform".to_string(), + )) + } } diff --git a/plugins/clipboard-manager/src/models.rs b/plugins/clipboard-manager/src/models.rs index a223a679da..f4bff3f291 100644 --- a/plugins/clipboard-manager/src/models.rs +++ b/plugins/clipboard-manager/src/models.rs @@ -8,10 +8,12 @@ use serde::{Deserialize, Serialize}; #[serde(rename_all = "camelCase")] pub enum ClipKind { PlainText { label: Option, text: String }, + Html { html: String, alt_html: Option } } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum ClipboardContents { PlainText { text: String }, + Html { html: String, alt_html: Option } } From 77dec43d86b8ccb802b0f61fde88586b1f52927e Mon Sep 17 00:00:00 2001 From: TukanDev Date: Thu, 22 Feb 2024 00:47:43 +0100 Subject: [PATCH 02/17] Update readme of clipboard plugin Signed-off-by: TukanDev --- plugins/clipboard-manager/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/clipboard-manager/README.md b/plugins/clipboard-manager/README.md index 70ad717fd1..0b10cb4565 100644 --- a/plugins/clipboard-manager/README.md +++ b/plugins/clipboard-manager/README.md @@ -60,9 +60,15 @@ fn main() { Afterwards all the plugin's APIs are available through the JavaScript guest bindings: ```javascript -import { writeText, readText } from "@tauri-apps/plugin-clipboard-manager"; +import { writeText, readText, writeHtml, readHtml, clear } from "@tauri-apps/plugin-clipboard-manager"; await writeText("Tauri is awesome!"); assert(await readText(), "Tauri is awesome!"); + +// 2nd parameter is alternative text that is treated as plain text +await writeHtml('

Tauri is awesome!

', '

Tauri is awesome!

') +assert(await readHtml(), "

Tauri is awesome!

"); + +await clear() ``` ## Contributing From 0b09072e49cfaaf7ad77db5d8887dc17bc17e7d8 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Fri, 23 Feb 2024 20:20:06 +0000 Subject: [PATCH 03/17] Update plugins/clipboard-manager/src/desktop.rs Propagate error for clear as requested Co-authored-by: Amr Bashir --- plugins/clipboard-manager/src/desktop.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/clipboard-manager/src/desktop.rs b/plugins/clipboard-manager/src/desktop.rs index 4821abfac5..4a99e4e5d5 100644 --- a/plugins/clipboard-manager/src/desktop.rs +++ b/plugins/clipboard-manager/src/desktop.rs @@ -73,8 +73,7 @@ impl Clipboard { pub fn clear(&self) -> crate::Result<()> { match &self.clipboard { Ok(clipboard) => { - clipboard.lock().unwrap().clear().unwrap(); - Ok(()) + clipboard.lock().unwrap().clear().map_err(Into::into) } Err(e) => Err(crate::Error::Clipboard(e.to_string())), } From fe4c3a1873b135189d405d7e36429ac1d70f5ee1 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Fri, 23 Feb 2024 20:21:07 +0000 Subject: [PATCH 04/17] Update plugins/clipboard-manager/guest-js/index.ts Change to camelCase as requested Co-authored-by: Amr Bashir --- plugins/clipboard-manager/guest-js/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/clipboard-manager/guest-js/index.ts b/plugins/clipboard-manager/guest-js/index.ts index cd94540bfd..7db5cb6c05 100644 --- a/plugins/clipboard-manager/guest-js/index.ts +++ b/plugins/clipboard-manager/guest-js/index.ts @@ -70,13 +70,13 @@ async function readText(): Promise { */ async function writeHtml( html: string, - alt_html: string + altHtml?: string ): Promise { return invoke("plugin:clipboard-manager|write_html", { data: { html: { html, - alt_html + altHtml }, }, }); From a089423ac6603000eb26c1c4162d7089138a46bb Mon Sep 17 00:00:00 2001 From: TukanDev Date: Fri, 23 Feb 2024 20:21:59 +0000 Subject: [PATCH 05/17] Update plugins/clipboard-manager/guest-js/index.ts use camelCase here too Co-authored-by: Amr Bashir --- plugins/clipboard-manager/guest-js/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/clipboard-manager/guest-js/index.ts b/plugins/clipboard-manager/guest-js/index.ts index 7db5cb6c05..d705eac280 100644 --- a/plugins/clipboard-manager/guest-js/index.ts +++ b/plugins/clipboard-manager/guest-js/index.ts @@ -11,7 +11,7 @@ import { invoke } from "@tauri-apps/api/core"; type ClipResponse = Record<"plainText", { text: string }>; -type ClipHtmlResponse = Record<"html", { html: string, alt_html: string }>; +type ClipHtmlResponse = Record<"html", { html: string, altHtml: string }>; /** * Writes plain text to the clipboard. From c76ef43c1ba110ef749f35ddf095aae8dacdcebe Mon Sep 17 00:00:00 2001 From: TukanDev Date: Fri, 23 Feb 2024 20:34:06 +0000 Subject: [PATCH 06/17] Update README.md Revert back as mentioned in HTML PR --- plugins/clipboard-manager/README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/clipboard-manager/README.md b/plugins/clipboard-manager/README.md index 0b10cb4565..b1b0f65fb5 100644 --- a/plugins/clipboard-manager/README.md +++ b/plugins/clipboard-manager/README.md @@ -63,12 +63,6 @@ Afterwards all the plugin's APIs are available through the JavaScript guest bind import { writeText, readText, writeHtml, readHtml, clear } from "@tauri-apps/plugin-clipboard-manager"; await writeText("Tauri is awesome!"); assert(await readText(), "Tauri is awesome!"); - -// 2nd parameter is alternative text that is treated as plain text -await writeHtml('

Tauri is awesome!

', '

Tauri is awesome!

') -assert(await readHtml(), "

Tauri is awesome!

"); - -await clear() ``` ## Contributing From a39b4e35822e94ecadb4c810403ddd1c067d98b5 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Fri, 23 Feb 2024 20:40:25 +0000 Subject: [PATCH 07/17] Update index.ts After discussion readHtml() is decided to be removed. Will follow and remove corresponding rust side function too. --- plugins/clipboard-manager/guest-js/index.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/plugins/clipboard-manager/guest-js/index.ts b/plugins/clipboard-manager/guest-js/index.ts index d705eac280..077a58c1c8 100644 --- a/plugins/clipboard-manager/guest-js/index.ts +++ b/plugins/clipboard-manager/guest-js/index.ts @@ -82,20 +82,6 @@ async function writeHtml( }); } -/** - * Gets the clipboard content as HTML text. - * @example - * ```typescript - * import { readHtml } from '@tauri-apps/plugin-clipboard-manager'; - * const clipboardHtml = await readHtml(); - * ``` - * @since 2.0.0 - */ -async function readHtml(): Promise { - const kind: ClipHtmlResponse = await invoke("plugin:clipboard-manager|read_html"); - return kind.html -} - /** * Gets the clipboard content as HTML text. * @example @@ -110,4 +96,4 @@ async function clear(): Promise { return; } -export { writeText, readText, writeHtml, readHtml, clear }; +export { writeText, readText, writeHtml, clear }; From 97b73acb046721e4b8188ca46b823e8e9073af39 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Fri, 23 Feb 2024 21:47:43 +0100 Subject: [PATCH 08/17] Strip all other existence of read_html out as determined in HTML support PR conversation Signed-off-by: TukanDev --- plugins/clipboard-manager/guest-js/index.ts | 3 ++- plugins/clipboard-manager/src/commands.rs | 8 -------- plugins/clipboard-manager/src/desktop.rs | 11 ----------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/plugins/clipboard-manager/guest-js/index.ts b/plugins/clipboard-manager/guest-js/index.ts index 077a58c1c8..19ea4f4cc7 100644 --- a/plugins/clipboard-manager/guest-js/index.ts +++ b/plugins/clipboard-manager/guest-js/index.ts @@ -11,7 +11,8 @@ import { invoke } from "@tauri-apps/api/core"; type ClipResponse = Record<"plainText", { text: string }>; -type ClipHtmlResponse = Record<"html", { html: string, altHtml: string }>; +// Commented this type out as it can come in handy to stay +//type ClipHtmlResponse = Record<"html", { html: string, altHtml: string }>; /** * Writes plain text to the clipboard. diff --git a/plugins/clipboard-manager/src/commands.rs b/plugins/clipboard-manager/src/commands.rs index 49c459a3ed..d7fb06888c 100644 --- a/plugins/clipboard-manager/src/commands.rs +++ b/plugins/clipboard-manager/src/commands.rs @@ -32,14 +32,6 @@ pub(crate) async fn write_html( clipboard.write_html(data) } -#[command] -pub(crate) async fn read_html( - _app: AppHandle, - clipboard: State<'_, Clipboard>, -) -> Result { - clipboard.read() -} - #[command] pub(crate) async fn clear( _app: AppHandle, diff --git a/plugins/clipboard-manager/src/desktop.rs b/plugins/clipboard-manager/src/desktop.rs index 4a99e4e5d5..86ff08628d 100644 --- a/plugins/clipboard-manager/src/desktop.rs +++ b/plugins/clipboard-manager/src/desktop.rs @@ -59,17 +59,6 @@ impl Clipboard { } } - pub fn read_html(&self) -> crate::Result { - match &self.clipboard { - Ok(clipboard) => { - let html = clipboard.lock().unwrap().get_text()?; - // arboard does not have read_html() as its just text, therefor unable to populate alt_html in this case - Ok(ClipboardContents::Html { html, alt_html: None }) - } - Err(e) => Err(crate::Error::Clipboard(e.to_string())), - } - } - pub fn clear(&self) -> crate::Result<()> { match &self.clipboard { Ok(clipboard) => { From 64e8b35433d49d6b5883190e0aacfa2c35f3c1be Mon Sep 17 00:00:00 2001 From: TukanDev Date: Sat, 24 Feb 2024 18:03:28 +0100 Subject: [PATCH 09/17] Apply requested changes v2 Signed-off-by: TukanDev --- plugins/clipboard-manager/guest-js/index.ts | 10 ++++------ plugins/clipboard-manager/src/models.rs | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/clipboard-manager/guest-js/index.ts b/plugins/clipboard-manager/guest-js/index.ts index 19ea4f4cc7..4cc104dae1 100644 --- a/plugins/clipboard-manager/guest-js/index.ts +++ b/plugins/clipboard-manager/guest-js/index.ts @@ -11,8 +11,6 @@ import { invoke } from "@tauri-apps/api/core"; type ClipResponse = Record<"plainText", { text: string }>; -// Commented this type out as it can come in handy to stay -//type ClipHtmlResponse = Record<"html", { html: string, altHtml: string }>; /** * Writes plain text to the clipboard. @@ -62,7 +60,7 @@ async function readText(): Promise { * import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager'; * await writeHtml('

Tauri is awesome!

', 'plaintext'); * await writeHtml('

Tauri is awesome!

', '

Tauri is awesome

'); // Will write "

Tauri is awesome

" as plain text - * assert(await readHtml(), '

Tauri is awesome!

'); + * assert(await readText(), '

Tauri is awesome!

'); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -84,11 +82,11 @@ async function writeHtml( } /** - * Gets the clipboard content as HTML text. + * Clears the clipboard. * @example * ```typescript - * import { readHtml } from '@tauri-apps/plugin-clipboard-manager'; - * const clipboardHtml = await readHtml(); + * import { clear } from '@tauri-apps/plugin-clipboard-manager'; + * await clear(); * ``` * @since 2.0.0 */ diff --git a/plugins/clipboard-manager/src/models.rs b/plugins/clipboard-manager/src/models.rs index f4bff3f291..110ab3334b 100644 --- a/plugins/clipboard-manager/src/models.rs +++ b/plugins/clipboard-manager/src/models.rs @@ -14,6 +14,5 @@ pub enum ClipKind { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum ClipboardContents { - PlainText { text: String }, - Html { html: String, alt_html: Option } + PlainText { text: String } } From 1312cb073f245d799fd9b14fc8ee18a8b7471690 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Sun, 25 Feb 2024 18:11:40 +0100 Subject: [PATCH 10/17] pnpm run build and cargo fmt Signed-off-by: TukanDev --- plugins/clipboard-manager/src/api-iife.js | 2 +- plugins/clipboard-manager/src/desktop.rs | 24 +++++++++++------------ plugins/clipboard-manager/src/lib.rs | 2 -- plugins/clipboard-manager/src/models.rs | 12 +++++++++--- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/plugins/clipboard-manager/src/api-iife.js b/plugins/clipboard-manager/src/api-iife.js index 8dc5165519..bbf9cff628 100644 --- a/plugins/clipboard-manager/src/api-iife.js +++ b/plugins/clipboard-manager/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_PLUGIN_CLIPBOARDMANAGER__=function(e){"use strict";async function n(e,n={},r){return window.__TAURI_INTERNALS__.invoke(e,n,r)}return"function"==typeof SuppressedError&&SuppressedError,e.readText=async function(){return(await n("plugin:clipboard-manager|read")).plainText.text},e.writeText=async function(e,r){return n("plugin:clipboard-manager|write",{data:{plainText:{label:r?.label,text:e}}})},e}({});Object.defineProperty(window.__TAURI__,"clipboardManager",{value:__TAURI_PLUGIN_CLIPBOARDMANAGER__})} +if("__TAURI__"in window){var __TAURI_PLUGIN_CLIPBOARDMANAGER__=function(n){"use strict";async function r(n,r={},a){return window.__TAURI_INTERNALS__.invoke(n,r,a)}return"function"==typeof SuppressedError&&SuppressedError,n.clear=async function(){await r("plugin:clipboard-manager|clear")},n.readText=async function(){return(await r("plugin:clipboard-manager|read")).plainText.text},n.writeHtml=async function(n,a){return r("plugin:clipboard-manager|write_html",{data:{html:{html:n,altHtml:a}}})},n.writeText=async function(n,a){return r("plugin:clipboard-manager|write",{data:{plainText:{label:a?.label,text:n}}})},n}({});Object.defineProperty(window.__TAURI__,"clipboardManager",{value:__TAURI_PLUGIN_CLIPBOARDMANAGER__})} diff --git a/plugins/clipboard-manager/src/desktop.rs b/plugins/clipboard-manager/src/desktop.rs index 86ff08628d..acf63c800b 100644 --- a/plugins/clipboard-manager/src/desktop.rs +++ b/plugins/clipboard-manager/src/desktop.rs @@ -29,12 +29,10 @@ pub struct Clipboard { impl Clipboard { pub fn write(&self, kind: ClipKind) -> crate::Result<()> { match kind { - ClipKind::PlainText { text, .. } => { - match &self.clipboard { - Ok(clipboard) => clipboard.lock().unwrap().set_text(text).map_err(Into::into), - Err(e) => Err(crate::Error::Clipboard(e.to_string())), - } - } + ClipKind::PlainText { text, .. } => match &self.clipboard { + Ok(clipboard) => clipboard.lock().unwrap().set_text(text).map_err(Into::into), + Err(e) => Err(crate::Error::Clipboard(e.to_string())), + }, _ => Err(crate::Error::Clipboard("Invalid clip kind!".to_string())), } } @@ -52,18 +50,20 @@ impl Clipboard { pub fn write_html(&self, kind: ClipKind) -> crate::Result<()> { match kind { ClipKind::Html { html, alt_html, .. } => match &self.clipboard { - Ok(clipboard) => clipboard.lock().unwrap().set_html(html, alt_html).map_err(Into::into), + Ok(clipboard) => clipboard + .lock() + .unwrap() + .set_html(html, alt_html) + .map_err(Into::into), Err(e) => Err(crate::Error::Clipboard(e.to_string())), - } + }, _ => Err(crate::Error::Clipboard("Invalid clip kind!".to_string())), - } } + } pub fn clear(&self) -> crate::Result<()> { match &self.clipboard { - Ok(clipboard) => { - clipboard.lock().unwrap().clear().map_err(Into::into) - } + Ok(clipboard) => clipboard.lock().unwrap().clear().map_err(Into::into), Err(e) => Err(crate::Error::Clipboard(e.to_string())), } } diff --git a/plugins/clipboard-manager/src/lib.rs b/plugins/clipboard-manager/src/lib.rs index 3f830e161b..bbfe591897 100644 --- a/plugins/clipboard-manager/src/lib.rs +++ b/plugins/clipboard-manager/src/lib.rs @@ -55,8 +55,6 @@ pub fn init() -> TauriPlugin { #[cfg(desktop)] commands::write_html, #[cfg(desktop)] - commands::read_html, - #[cfg(desktop)] commands::clear ]) .setup(|app, api| { diff --git a/plugins/clipboard-manager/src/models.rs b/plugins/clipboard-manager/src/models.rs index 110ab3334b..bb8c9b543d 100644 --- a/plugins/clipboard-manager/src/models.rs +++ b/plugins/clipboard-manager/src/models.rs @@ -7,12 +7,18 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum ClipKind { - PlainText { label: Option, text: String }, - Html { html: String, alt_html: Option } + PlainText { + label: Option, + text: String, + }, + Html { + html: String, + alt_html: Option, + }, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum ClipboardContents { - PlainText { text: String } + PlainText { text: String }, } From 164cae96ce0dbd56dc34ae552f247614cff801db Mon Sep 17 00:00:00 2001 From: TukanDev Date: Sun, 25 Feb 2024 17:28:12 +0000 Subject: [PATCH 11/17] Update plugins/clipboard-manager/src/mobile.rs fix ci calling Co-authored-by: Amr Bashir --- plugins/clipboard-manager/src/mobile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/clipboard-manager/src/mobile.rs b/plugins/clipboard-manager/src/mobile.rs index 970a95975d..9a8b0b401f 100644 --- a/plugins/clipboard-manager/src/mobile.rs +++ b/plugins/clipboard-manager/src/mobile.rs @@ -41,7 +41,7 @@ impl Clipboard { } // Treat HTML as unsupported on mobile until tested - pub fn write_html(&self) -> crate::Result { + pub fn write_html(&self, _kind: ClipKind) -> crate::Result { Err(crate::Error::Clipboard( "Unsupported on this platform".to_string(), )) From ce9c6df9af95cddf59ca4ba53e5bb77f16c6b366 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Sun, 25 Feb 2024 18:29:11 +0100 Subject: [PATCH 12/17] mobile read_html omg.... Signed-off-by: TukanDev --- plugins/clipboard-manager/src/mobile.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/clipboard-manager/src/mobile.rs b/plugins/clipboard-manager/src/mobile.rs index 970a95975d..5eab926ffc 100644 --- a/plugins/clipboard-manager/src/mobile.rs +++ b/plugins/clipboard-manager/src/mobile.rs @@ -46,10 +46,4 @@ impl Clipboard { "Unsupported on this platform".to_string(), )) } - - pub fn read_html(&self) -> crate::Result { - Err(crate::Error::Clipboard( - "Unsupported on this platform".to_string(), - )) - } } From f4d52da3711d0ca4b44d383dc981e18cf6a18722 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 25 Feb 2024 19:32:53 +0200 Subject: [PATCH 13/17] Update plugins/clipboard-manager/src/mobile.rs --- plugins/clipboard-manager/src/mobile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/clipboard-manager/src/mobile.rs b/plugins/clipboard-manager/src/mobile.rs index 1a765a224b..2aeae88575 100644 --- a/plugins/clipboard-manager/src/mobile.rs +++ b/plugins/clipboard-manager/src/mobile.rs @@ -41,7 +41,7 @@ impl Clipboard { } // Treat HTML as unsupported on mobile until tested - pub fn write_html(&self, _kind: ClipKind) -> crate::Result { + pub fn write_html(&self, _kind: ClipKind) -> crate::Result<()> { Err(crate::Error::Clipboard( "Unsupported on this platform".to_string(), )) From 26b5c7ecfb215c505fce3f0ba51918431ce1d929 Mon Sep 17 00:00:00 2001 From: TukanDev Date: Sun, 25 Feb 2024 18:34:50 +0100 Subject: [PATCH 14/17] pnpm format.... Signed-off-by: TukanDev --- plugins/clipboard-manager/guest-js/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/clipboard-manager/guest-js/index.ts b/plugins/clipboard-manager/guest-js/index.ts index 4cc104dae1..c812ad539b 100644 --- a/plugins/clipboard-manager/guest-js/index.ts +++ b/plugins/clipboard-manager/guest-js/index.ts @@ -67,15 +67,12 @@ async function readText(): Promise { * * @since 2.0.0 */ -async function writeHtml( - html: string, - altHtml?: string -): Promise { +async function writeHtml(html: string, altHtml?: string): Promise { return invoke("plugin:clipboard-manager|write_html", { data: { html: { html, - altHtml + altHtml, }, }, }); From 291614fc9dc5f99ab4aacded09c07e5c248c0623 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 25 Feb 2024 19:38:11 +0200 Subject: [PATCH 15/17] error on mobile as well --- plugins/clipboard-manager/src/error.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/clipboard-manager/src/error.rs b/plugins/clipboard-manager/src/error.rs index bf71802fec..03da585b0b 100644 --- a/plugins/clipboard-manager/src/error.rs +++ b/plugins/clipboard-manager/src/error.rs @@ -11,7 +11,6 @@ pub enum Error { #[cfg(mobile)] #[error(transparent)] PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError), - #[cfg(desktop)] #[error("{0}")] Clipboard(String), } From 0a4b6b05f991d0f738541c13a5b56de3b4dedf0f Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 25 Feb 2024 19:40:50 +0200 Subject: [PATCH 16/17] clear on mobile --- plugins/clipboard-manager/src/mobile.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/clipboard-manager/src/mobile.rs b/plugins/clipboard-manager/src/mobile.rs index 2aeae88575..8ba8c809de 100644 --- a/plugins/clipboard-manager/src/mobile.rs +++ b/plugins/clipboard-manager/src/mobile.rs @@ -46,4 +46,10 @@ impl Clipboard { "Unsupported on this platform".to_string(), )) } + + pub fn clear(&self) -> crate::Result<()> { + Err(crate::Error::Clipboard( + "Unsupported on this platform".to_string(), + )) + } } From cb85453ce1493579bc2ba8ecf52c796cfe37e76f Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 25 Feb 2024 19:45:23 +0200 Subject: [PATCH 17/17] change file [skip ci] --- .changes/clipboard-html.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/clipboard-html.md diff --git a/.changes/clipboard-html.md b/.changes/clipboard-html.md new file mode 100644 index 0000000000..df19abfd5a --- /dev/null +++ b/.changes/clipboard-html.md @@ -0,0 +1,6 @@ +--- +"clipboard-manager": patch +"clipboard-manager-js": patch +--- + +Add support for writing HTML content to the clipboard. \ No newline at end of file