From 26d6128c762cc884efe10f793ce626e35dfd3bea Mon Sep 17 00:00:00 2001 From: ChurchTao Date: Mon, 22 Jul 2024 18:11:26 +0800 Subject: [PATCH 1/3] -Fix: Bug: When read rimeout on Linux there is throw error but not loop [issues#30](https://github.com/ChurchTao/clipboard-rs/issues/30) --- CHANGELOG.md | 34 ++++++++++++++++++++++++---------- Cargo.toml | 6 +++--- src/lib.rs | 1 + src/platform/win.rs | 18 ++++++++++-------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a2a68..f10990d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,32 +1,46 @@ # Changelog +## v0.1.9 (2024-07-22) [released] + +- Fix: Bug: `set` on windows without clear [issues#32](https://github.com/ChurchTao/clipboard-rs/issues/32) + ## v0.1.8 (2024-07-18) [released] --Fix: Bug: When read rimeout on Linux there is throw error but not loop [issues#30](https://github.com/ChurchTao/clipboard-rs/issues/30) +- Fix: Bug: When read rimeout on Linux there is throw error but not + loop [issues#30](https://github.com/ChurchTao/clipboard-rs/issues/30) ## v0.1.7 (2024-04-30) [released] --Fix: Bug: Cannot write all content when writing to html on Windows [issues#23](https://github.com/ChurchTao/clipboard-rs/issues/23) +- Fix: Bug: Cannot write all content when writing to html on + Windows [issues#23](https://github.com/ChurchTao/clipboard-rs/issues/23) ## v0.1.6 (2024-04-12) [released] -- Fix: Bug: Cannot paste after writing image to clipboard (on Windows) #17 [issues#17](https://github.com/ChurchTao/clipboard-rs/issues/17) -- Fix: Bug: No transparent background for clipboard image read on Windows #18 [issues#18](https://github.com/ChurchTao/clipboard-rs/issues/18) -- Fix: Bug: Cannot read clipboard image on MacOS for screenshots taken by certain apps #19 [issues#19](https://github.com/ChurchTao/clipboard-rs/issues/19) +- Fix: Bug: Cannot paste after writing image to clipboard (on Windows) + #17 [issues#17](https://github.com/ChurchTao/clipboard-rs/issues/17) +- Fix: Bug: No transparent background for clipboard image read on Windows + #18 [issues#18](https://github.com/ChurchTao/clipboard-rs/issues/18) +- Fix: Bug: Cannot read clipboard image on MacOS for screenshots taken by certain apps + #19 [issues#19](https://github.com/ChurchTao/clipboard-rs/issues/19) ## v0.1.5 (2024-04-11) [released] -- Fix: Fix the bug `fn get_image()` where image type is `CF_DIBV5` in `win11`. [issues#14](https://github.com/ChurchTao/clipboard-rs/issues/14) +- Fix: Fix the bug `fn get_image()` where image type is `CF_DIBV5` + in `win11`. [issues#14](https://github.com/ChurchTao/clipboard-rs/issues/14) ## v0.1.4 (2024-03-18) [released] -- Fix: Fix the bug `fn read_files()` where no files in clipboard. [issues#11](https://github.com/ChurchTao/clipboard-rs/issues/11) +- Fix: Fix the bug `fn read_files()` where no files in + clipboard. [issues#11](https://github.com/ChurchTao/clipboard-rs/issues/11) ## v0.1.3 (2024-03-14) [released] -- Fix: Fix the bug on `Windows` can't read DIBV5 format image from clipboard [issues#8](https://github.com/ChurchTao/clipboard-rs/issues/8) -- Fix: Fix the bug on `Windows` can't move `WatcherContext` to another thread [issues#4](https://github.com/ChurchTao/clipboard-rs/issues/4) -- Change: Demo `watch_change.rs` The callback function for monitoring changes in the clipboard is changed to implement a trait. [pr#6](https://github.com/ChurchTao/clipboard-rs/pull/6) +- Fix: Fix the bug on `Windows` can't read DIBV5 format image from + clipboard [issues#8](https://github.com/ChurchTao/clipboard-rs/issues/8) +- Fix: Fix the bug on `Windows` can't move `WatcherContext` to another + thread [issues#4](https://github.com/ChurchTao/clipboard-rs/issues/4) +- Change: Demo `watch_change.rs` The callback function for monitoring changes in the clipboard is changed to implement a + trait. [pr#6](https://github.com/ChurchTao/clipboard-rs/pull/6) ## v0.1.2 (2024-03-08) [released] diff --git a/Cargo.toml b/Cargo.toml index 6c3347f..ef1f9fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clipboard-rs" -version = "0.1.8" +version = "0.1.9" authors = ["ChurchTao "] description = "Cross-platform clipboard API (text | image | rich text | html | files | monitoring changes) | 跨平台剪贴板 API(文本|图片|富文本|html|文件|监听变化) Windows,MacOS,Linux" repository = "https://github.com/ChurchTao/clipboard-rs" @@ -12,10 +12,10 @@ edition = "2021" rust-version = "1.63.0" [dependencies] -image = "0.25" +image = "0.25.2" [target.'cfg(target_os = "windows")'.dependencies] -clipboard-win = { version = "5.3.1", features = ["monitor"] } +clipboard-win = { version = "5.4.0", features = ["monitor"] } [target.'cfg(target_os = "macos")'.dependencies] cocoa = "0.25.0" diff --git a/src/lib.rs b/src/lib.rs index 4573437..3b54bfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,7 @@ pub trait Clipboard: Send { fn set_files(&self, files: Vec) -> Result<()>; + /// set image will clear clipboard fn set(&self, contents: Vec) -> Result<()>; } diff --git a/src/platform/win.rs b/src/platform/win.rs index 52fd569..4832b9b 100644 --- a/src/platform/win.rs +++ b/src/platform/win.rs @@ -1,11 +1,11 @@ use crate::common::{ContentData, Result, RustImage, RustImageData}; use crate::{Clipboard, ClipboardContent, ClipboardHandler, ClipboardWatcher, ContentFormat}; use clipboard_win::formats::{CF_DIB, CF_DIBV5}; -use clipboard_win::raw::set_without_clear; +use clipboard_win::raw::{set_file_list, set_file_list_with, set_string_with, set_without_clear}; use clipboard_win::types::c_uint; use clipboard_win::{ - formats, get, get_clipboard, raw, set_clipboard, Clipboard as ClipboardWin, Monitor, Setter, - SysResult, + formats, get, get_clipboard, options, raw, set_clipboard, Clipboard as ClipboardWin, Monitor, + Setter, SysResult, }; use image::codecs::bmp::BmpDecoder; use image::{DynamicImage, EncodableLayout}; @@ -355,19 +355,21 @@ impl Clipboard for ClipboardContext { fn set_files(&self, files: Vec) -> Result<()> { let _clip = ClipboardWin::new_attempts(10) .map_err(|code| format!("Open clipboard error, code = {}", code)); - let res = formats::FileList.write_clipboard(&files); + let res = set_file_list_with(&files, options::DoClear); res.map_err(|e| format!("set files error, code = {}", e).into()) } fn set(&self, contents: Vec) -> Result<()> { let _clip = ClipboardWin::new_attempts(10) .map_err(|code| format!("Open clipboard error, code = {}", code)); + let res = clipboard_win::empty(); + if let Err(e) = res { + return Err(format!("Empty clipboard error, code = {}", e).into()); + } for content in contents { match content { ClipboardContent::Text(txt) => { - let format_uint = formats::CF_UNICODETEXT; - let u16_str = utf8_to_utf16(txt.as_str()); - let res = set_without_clear(format_uint, u16_str.as_bytes()); + let res = set_string_with(txt.as_str(), options::NoClear); if res.is_err() { continue; } @@ -394,7 +396,7 @@ impl Clipboard for ClipboardContext { } } ClipboardContent::Files(file_list) => { - let res = formats::FileList.write_clipboard(&file_list); + let res = set_file_list_with(&file_list, options::NoClear); if res.is_err() { continue; } From d43b92939f45bafe40520f1a37a0ef0e0ca4ed33 Mon Sep 17 00:00:00 2001 From: ChurchTao Date: Mon, 22 Jul 2024 18:40:59 +0800 Subject: [PATCH 2/3] fix import --- src/platform/win.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/platform/win.rs b/src/platform/win.rs index 4832b9b..def74cf 100644 --- a/src/platform/win.rs +++ b/src/platform/win.rs @@ -1,19 +1,21 @@ -use crate::common::{ContentData, Result, RustImage, RustImageData}; -use crate::{Clipboard, ClipboardContent, ClipboardHandler, ClipboardWatcher, ContentFormat}; +use std::collections::HashMap; +use std::io::Cursor; +use std::sync::mpsc::{Receiver, Sender}; +use std::thread; +use std::time::Duration; + use clipboard_win::formats::{CF_DIB, CF_DIBV5}; -use clipboard_win::raw::{set_file_list, set_file_list_with, set_string_with, set_without_clear}; +use clipboard_win::raw::{set_file_list_with, set_string_with, set_without_clear}; use clipboard_win::types::c_uint; use clipboard_win::{ formats, get, get_clipboard, options, raw, set_clipboard, Clipboard as ClipboardWin, Monitor, - Setter, SysResult, + SysResult, }; use image::codecs::bmp::BmpDecoder; use image::{DynamicImage, EncodableLayout}; -use std::collections::HashMap; -use std::io::Cursor; -use std::sync::mpsc::{Receiver, Sender}; -use std::thread; -use std::time::Duration; + +use crate::common::{ContentData, Result, RustImage, RustImageData}; +use crate::{Clipboard, ClipboardContent, ClipboardHandler, ClipboardWatcher, ContentFormat}; pub struct WatcherShutdown { stop_signal: Sender<()>, From dcb46a0b4d22ee9fb09698477f4e8d4ccef4528f Mon Sep 17 00:00:00 2001 From: ChurchTao Date: Mon, 22 Jul 2024 18:42:54 +0800 Subject: [PATCH 3/3] fix import --- src/platform/win.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platform/win.rs b/src/platform/win.rs index def74cf..fdafdb4 100644 --- a/src/platform/win.rs +++ b/src/platform/win.rs @@ -12,7 +12,7 @@ use clipboard_win::{ SysResult, }; use image::codecs::bmp::BmpDecoder; -use image::{DynamicImage, EncodableLayout}; +use image::DynamicImage; use crate::common::{ContentData, Result, RustImage, RustImageData}; use crate::{Clipboard, ClipboardContent, ClipboardHandler, ClipboardWatcher, ContentFormat}; @@ -467,11 +467,11 @@ impl Drop for WatcherShutdown { } /// 将输入的 UTF-8 字符串转换为宽字符(UTF-16)字符串 -fn utf8_to_utf16(input: &str) -> Vec { - let mut vec: Vec = input.encode_utf16().collect(); - vec.push(0); - vec -} +// fn utf8_to_utf16(input: &str) -> Vec { +// let mut vec: Vec = input.encode_utf16().collect(); +// vec.push(0); +// vec +// } // https://learn.microsoft.com/en-us/windows/win32/dataxchg/html-clipboard-format // The description header includes the clipboard version number and offsets, indicating where the context and the fragment start and end. The description is a list of ASCII text keywords followed by a string and separated by a colon (:).