diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0b765cd..1ef1cd3 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -113,7 +113,7 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix", + "rustix 1.0.8", "slab", "windows-sys 0.60.2", ] @@ -144,7 +144,7 @@ dependencies = [ "cfg-if", "event-listener", "futures-lite", - "rustix", + "rustix 1.0.8", ] [[package]] @@ -170,7 +170,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix", + "rustix 1.0.8", "signal-hook-registry", "slab", "windows-sys 0.60.2", @@ -277,6 +277,28 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bindgen" +version = "0.64.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 1.0.109", + "which", +] + [[package]] name = "bit_field" version = "0.10.2" @@ -474,6 +496,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfb" version = "0.7.3" @@ -520,6 +551,17 @@ dependencies = [ "windows-link", ] +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading 0.8.8", +] + [[package]] name = "clipboard" version = "0.5.0" @@ -961,7 +1003,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading", + "libloading 0.7.4", ] [[package]] @@ -1008,7 +1050,9 @@ dependencies = [ "tauri", "tauri-build", "tauri-plugin-opener", + "tesseract", "tokio", + "uuid", ] [[package]] @@ -1734,6 +1778,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "html5ever" version = "0.29.1" @@ -2231,12 +2284,40 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "lebe" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" +[[package]] +name = "leptonica-plumbing" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7a74c43d6f090d39158d233f326f47cd8bba545217595c93662b4e31156f42" +dependencies = [ + "leptonica-sys", + "libc", + "thiserror 1.0.69", +] + +[[package]] +name = "leptonica-sys" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da627c72b2499a8106f4dd33143843015e4a631f445d561f3481f7fba35b6151" +dependencies = [ + "bindgen", + "pkg-config", + "vcpkg", +] + [[package]] name = "libappindicator" version = "0.9.0" @@ -2257,7 +2338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e9ec52138abedcc58dc17a7c6c0c00a2bdb4f3427c7f63fa97fd0d859155caf" dependencies = [ "gtk-sys", - "libloading", + "libloading 0.7.4", "once_cell", ] @@ -2287,6 +2368,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "libloading" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" +dependencies = [ + "cfg-if", + "windows-targets 0.53.2", +] + [[package]] name = "libredox" version = "0.1.6" @@ -2314,6 +2405,12 @@ dependencies = [ "wayland-protocols-wlr", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "linux-raw-sys" version = "0.9.4" @@ -2465,6 +2562,12 @@ dependencies = [ "x11-dl", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -2604,6 +2707,16 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -3062,6 +3175,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3267,7 +3386,7 @@ dependencies = [ "concurrent-queue", "hermit-abi 0.5.2", "pin-project-lite", - "rustix", + "rustix 1.0.8", "windows-sys 0.60.2", ] @@ -3640,6 +3759,12 @@ version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.4.1" @@ -3649,6 +3774,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags 2.9.1", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + [[package]] name = "rustix" version = "1.0.8" @@ -3658,7 +3796,7 @@ dependencies = [ "bitflags 2.9.1", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.9.4", "windows-sys 0.60.2", ] @@ -4577,7 +4715,7 @@ dependencies = [ "fastrand", "getrandom 0.3.3", "once_cell", - "rustix", + "rustix 1.0.8", "windows-sys 0.59.0", ] @@ -4592,6 +4730,40 @@ dependencies = [ "utf-8", ] +[[package]] +name = "tesseract" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28e64963c0b5582cf02ed5d8b4798f8c48ea9812ed2b19ed653cb976e7daa351" +dependencies = [ + "tesseract-plumbing", + "tesseract-sys", + "thiserror 1.0.69", +] + +[[package]] +name = "tesseract-plumbing" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ed025d755abb7f5af8d16cd5663742a08c8ae7c4032c8bf4b70c51d412fe378" +dependencies = [ + "leptonica-plumbing", + "tesseract-sys", + "thiserror 1.0.69", +] + +[[package]] +name = "tesseract-sys" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e1297ece7aa841bd33a4f80046a6682c4e58fca0f8600e868d822359eef7bde" +dependencies = [ + "bindgen", + "leptonica-sys", + "pkg-config", + "vcpkg", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -5492,6 +5664,18 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a751b3277700db47d3e574514de2eced5e54dc8a5436a3bf7a0b248b2cee16f3" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix 0.38.44", +] + [[package]] name = "widestring" version = "1.2.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6e7b513..94fff7c 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -28,6 +28,8 @@ tokio = "1.46.1" clipboard = "0.5.0" screenshots = "0.8.10" minifb = "0.28.0" +tesseract = "0.15.2" +uuid = { version = "1.17.0", features = ["v4"] } [target."cfg(target_os = \"macos\")".dependencies] cocoa = "0.26.1" diff --git a/src-tauri/screenshot/screenshot_9d75ea90-5ac6-4814-b0c3-9f0534162a0e.png b/src-tauri/screenshot/screenshot_9d75ea90-5ac6-4814-b0c3-9f0534162a0e.png new file mode 100644 index 0000000..34e4897 Binary files /dev/null and b/src-tauri/screenshot/screenshot_9d75ea90-5ac6-4814-b0c3-9f0534162a0e.png differ diff --git a/src-tauri/screenshot/screenshot_c4a1ddd5-cf1f-47f4-a5bf-6dabcfa8e072.png b/src-tauri/screenshot/screenshot_c4a1ddd5-cf1f-47f4-a5bf-6dabcfa8e072.png new file mode 100644 index 0000000..b9698da Binary files /dev/null and b/src-tauri/screenshot/screenshot_c4a1ddd5-cf1f-47f4-a5bf-6dabcfa8e072.png differ diff --git a/src-tauri/src/commands/copy.rs b/src-tauri/src/commands/copy.rs index e637228..1eb744a 100644 --- a/src-tauri/src/commands/copy.rs +++ b/src-tauri/src/commands/copy.rs @@ -2,7 +2,7 @@ use clipboard::{ClipboardContext, ClipboardProvider}; #[tauri::command] pub fn copy(content: &str) { + let trimmed_content = content.trim_end(); let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); - - ctx.set_contents(content.to_string()).unwrap(); + ctx.set_contents(trimmed_content.to_string()).unwrap(); } \ No newline at end of file diff --git a/src-tauri/src/commands/screenshot.rs b/src-tauri/src/commands/screenshot.rs index ef28bc9..785fae9 100644 --- a/src-tauri/src/commands/screenshot.rs +++ b/src-tauri/src/commands/screenshot.rs @@ -1,43 +1,31 @@ -use minifb::{MouseButton, MouseMode, Window, WindowOptions}; +extern crate tesseract; use screenshots::Screen; -use std::cmp::min; +use uuid::Uuid; #[cfg(test)] mod tests { use super::*; #[test] - pub fn screenshot() { + pub fn screenshots() { let screens = Screen::all().unwrap(); - let primary_screen = screens.first().unwrap(); - let screen_width = primary_screen.display_info.width; - let screen_height = primary_screen.display_info.height; + for (_index, screen) in screens.iter().enumerate() { + // 捕获屏幕 + let screenshot = screen.capture().unwrap(); - // 创建透明窗口用于区域选择 - let mut window = Window::new( - "选择截图区域 - 按住鼠标左键拖动", - screen_width as usize, - screen_height as usize, - WindowOptions { - borderless: true, - transparency: true, - topmost: true, - ..WindowOptions::default() - }, - ) - .unwrap(); + // 保存截图,使用索引作为文件名的一部分 + let random_uuid = Uuid::new_v4(); + let filename = format!("screenshot/screenshot_{}.png", random_uuid); + screenshot.save(&filename).unwrap(); - println!("成功"); - } - - fn capture_area(x: i32, y: i32, width: u32, height: u32) { - let screens = Screen::all().unwrap(); - if let Some(screen) = screens.first() { - let image = screen.capture_area(x, y, width, height).unwrap(); - let filename = format!("area_{}x{}_{}x{}.png", x, y, width, height); - image.save(&filename).unwrap(); - println!("区域截图已保存为 {}", filename); + println!("截图: {}", filename); } } } + +fn ocr() { + let output_text = tesseract::ocr("/Users/wangyijia/Desktop/wecom-temp-219286-5e1060a3022e70398ee52d83e6cdfc63.jpg", "chi_sim").unwrap(); + + println!("识别结果:\n{}", output_text); +} \ No newline at end of file