From 0eabe57dc7b011b4084bd4de4c5b6fe95b99215c Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Tue, 14 May 2024 17:12:28 -0400 Subject: [PATCH 1/9] fill in dummy Get::html() implementation for Windows --- src/platform/windows.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index d229e94..078b447 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -10,7 +10,7 @@ and conditions of the chosen license apply to this file. #[cfg(feature = "image-data")] use crate::common::ImageData; -use crate::common::{private, Error}; +use crate::common::{private, Error, HTMLData}; use std::{borrow::Cow, marker::PhantomData, thread, time::Duration}; #[cfg(feature = "image-data")] @@ -522,6 +522,10 @@ impl<'clipboard> Get<'clipboard> { String::from_utf16(&out[..bytes_read]).map_err(|_| Error::ConversionFailure) } + pub(crate) fn html(self) -> Result { + self.text().map(|text| HTMLData { html: text.clone(), alt_text: text.clone() }) + } + #[cfg(feature = "image-data")] pub(crate) fn image(self) -> Result, Error> { const FORMAT: u32 = clipboard_win::formats::CF_DIBV5; From c1a487ae261f3d6b1331396c435d8f3eb57b425b Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Mon, 20 May 2024 16:24:32 -0400 Subject: [PATCH 2/9] bump clipboard-rs version --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a8051d2..3064e2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,9 +104,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clipboard-win" -version = "5.0.0" +version = "5.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c57002a5d9be777c1ef967e33674dac9ebd310d8893e4e3437b14d5f0f6372cc" +checksum = "79f4473f5144e20d9aceaf2972478f06ddf687831eafeeb434fbaf0acc4144ad" dependencies = [ "error-code", ] diff --git a/Cargo.toml b/Cargo.toml index 36af251..d9018b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ windows-sys = { version = "0.48.0", optional = true, features = [ "Win32_System_Memory", "Win32_System_Ole", ]} -clipboard-win = "5.0.0" +clipboard-win = "5.3.1" log = "0.4" [target.'cfg(target_os = "macos")'.dependencies] From 1ee60b4b5924d9396722462e825fda509145506f Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Mon, 20 May 2024 16:24:45 -0400 Subject: [PATCH 3/9] fetch HTML from clipboard --- src/platform/windows.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 078b447..2324943 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -8,6 +8,8 @@ the Apache 2.0 or the MIT license at the licensee's choice. The terms and conditions of the chosen license apply to this file. */ +use clipboard_win::{formats, Getter}; + #[cfg(feature = "image-data")] use crate::common::ImageData; use crate::common::{private, Error, HTMLData}; @@ -523,7 +525,35 @@ impl<'clipboard> Get<'clipboard> { } pub(crate) fn html(self) -> Result { - self.text().map(|text| HTMLData { html: text.clone(), alt_text: text.clone() }) + println!("called get_html"); + if let Some(format_code) = clipboard_win::register_format("HTML Format") { + println!("successfully registered HTML format"); + let _clipboard_assertion = self.clipboard?; + + if !clipboard_win::is_format_avail(format_code.get()) { + println!("HTML format was not available"); + return Err(Error::ContentNotAvailable); + } + + let html_format = formats::Html::new().unwrap(); + let mut html_out = String::new(); + html_format + .read_clipboard(&mut html_out) + .map(|bytes_read| { + println!( + "successfully read clipboard HTML data, {:?} bytes, contents {:?}", + bytes_read, html_out + ); + HTMLData::from_html(html_out) + }) + .map_err(|e| { + println!("failed to read clipboard HTML data, code {:?}", e); + Error::unknown(format!("failed to read clipboard HTML data, code {:?}", e)) + }) + } else { + println!("failed to register HTML format"); + Err(Error::ContentNotAvailable) + } } #[cfg(feature = "image-data")] From eef39aa65704488cdad899418107af96bcc51792 Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Mon, 20 May 2024 17:55:47 -0400 Subject: [PATCH 4/9] remove print statements --- src/platform/windows.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 2324943..bb89e40 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -525,13 +525,10 @@ impl<'clipboard> Get<'clipboard> { } pub(crate) fn html(self) -> Result { - println!("called get_html"); if let Some(format_code) = clipboard_win::register_format("HTML Format") { - println!("successfully registered HTML format"); let _clipboard_assertion = self.clipboard?; if !clipboard_win::is_format_avail(format_code.get()) { - println!("HTML format was not available"); return Err(Error::ContentNotAvailable); } @@ -539,19 +536,11 @@ impl<'clipboard> Get<'clipboard> { let mut html_out = String::new(); html_format .read_clipboard(&mut html_out) - .map(|bytes_read| { - println!( - "successfully read clipboard HTML data, {:?} bytes, contents {:?}", - bytes_read, html_out - ); - HTMLData::from_html(html_out) - }) + .map(|_| HTMLData::from_html(html_out)) .map_err(|e| { - println!("failed to read clipboard HTML data, code {:?}", e); Error::unknown(format!("failed to read clipboard HTML data, code {:?}", e)) }) } else { - println!("failed to register HTML format"); Err(Error::ContentNotAvailable) } } From c501e27be6d8372ffa85126a10b895ffcf3ad03b Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Mon, 20 May 2024 18:06:27 -0400 Subject: [PATCH 5/9] formatting again --- examples/get_html.rs | 2 +- examples/hello_html.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/get_html.rs b/examples/get_html.rs index a4b3424..7494dfe 100644 --- a/examples/get_html.rs +++ b/examples/get_html.rs @@ -6,4 +6,4 @@ fn main() { let html_data = ctx.get_html().unwrap(); println!("HTML data is:\n{:?}\nAlt text is:\n{:?}", html_data.html, html_data.alt_text); -} \ No newline at end of file +} diff --git a/examples/hello_html.rs b/examples/hello_html.rs index 71a52bc..9e73480 100644 --- a/examples/hello_html.rs +++ b/examples/hello_html.rs @@ -12,4 +12,4 @@ fn main() { "But now the clipboard text should be this HTML: \"{}\" with this alternate text: \"{}\"", html, alt_text ); -} \ No newline at end of file +} From 6cb9c4f1aefb1b391162bafcc74c3cf40b69e0a1 Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Tue, 21 May 2024 11:27:28 -0400 Subject: [PATCH 6/9] add MacOS stub --- src/platform/osx.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/platform/osx.rs b/src/platform/osx.rs index c48df73..f00ec43 100644 --- a/src/platform/osx.rs +++ b/src/platform/osx.rs @@ -210,6 +210,11 @@ impl<'clipboard> Get<'clipboard> { }) } + /// Unimplemented for now. + pub(crate) fn html(self) -> Result { + self.text().map(|string_data| HTMLData::from_alt_text(string_data)) + } + #[cfg(feature = "image-data")] pub(crate) fn image(self) -> Result, Error> { use objc_foundation::NSData; From 1093d6f06bc9aac4f4cd24d3abd5463a15e29c80 Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Tue, 21 May 2024 11:31:20 -0400 Subject: [PATCH 7/9] add import and format --- src/platform/osx.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/osx.rs b/src/platform/osx.rs index f00ec43..bf0d380 100644 --- a/src/platform/osx.rs +++ b/src/platform/osx.rs @@ -8,9 +8,9 @@ the Apache 2.0 or the MIT license at the licensee's choice. The terms and conditions of the chosen license apply to this file. */ -use crate::common::Error; #[cfg(feature = "image-data")] use crate::common::ImageData; +use crate::common::{Error, HTMLData}; #[cfg(feature = "image-data")] use core_graphics::{ base::{kCGBitmapByteOrderDefault, kCGImageAlphaLast, kCGRenderingIntentDefault, CGFloat}, @@ -212,7 +212,7 @@ impl<'clipboard> Get<'clipboard> { /// Unimplemented for now. pub(crate) fn html(self) -> Result { - self.text().map(|string_data| HTMLData::from_alt_text(string_data)) + self.text().map(HTMLData::from_alt_text) } #[cfg(feature = "image-data")] From b0817189af22656206bc03f6cdb73282ab555625 Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Tue, 21 May 2024 13:54:07 -0400 Subject: [PATCH 8/9] remove unused trait from macOS build --- src/common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common.rs b/src/common.rs index e61b636..5cc632d 100644 --- a/src/common.rs +++ b/src/common.rs @@ -185,6 +185,7 @@ impl Drop for ScopeGuard { } /// Common trait for sealing platform extension traits. +#[cfg(not(target_os = "macos"))] pub(crate) mod private { pub trait Sealed {} From 9febf307fe7d41da847de58bf473373f862de995 Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Tue, 21 May 2024 14:04:44 -0400 Subject: [PATCH 9/9] add TODO --- src/platform/osx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/osx.rs b/src/platform/osx.rs index bf0d380..3161729 100644 --- a/src/platform/osx.rs +++ b/src/platform/osx.rs @@ -210,7 +210,7 @@ impl<'clipboard> Get<'clipboard> { }) } - /// Unimplemented for now. + /// TODO: Implement get_html for MacOS. pub(crate) fn html(self) -> Result { self.text().map(HTMLData::from_alt_text) }