From 4be2d1103d9f4b46df9484cb423ec628777f257d Mon Sep 17 00:00:00 2001 From: David Armstrong Date: Tue, 14 Sep 2021 23:06:53 -0300 Subject: [PATCH] Added conditional logging Simplified Ctrl+V trigger --- Cargo.lock | 109 +---------------------------------------------------- Cargo.toml | 5 +-- src/lib.rs | 45 +++++++++++++--------- 3 files changed, 30 insertions(+), 129 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a425ba..e6b3151 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,12 +25,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "clap" version = "3.0.0-beta.4" @@ -73,56 +67,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "lazy_static", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" -dependencies = [ - "cfg-if", - "lazy_static", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - [[package]] name = "error-code" version = "2.3.0" @@ -135,12 +79,11 @@ dependencies = [ [[package]] name = "filo-clipboard" -version = "0.2.0" +version = "0.3.0" dependencies = [ "clap", "clipboard-win", "error-code", - "rayon", "winapi", ] @@ -190,25 +133,6 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" -[[package]] -name = "memoffset" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "os_str_bytes" version = "3.1.0" @@ -257,37 +181,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rayon" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" -dependencies = [ - "autocfg", - "crossbeam-deque", - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "lazy_static", - "num_cpus", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "str-buf" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index fdc235a..f768ca3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "filo-clipboard" -version = "0.2.0" +version = "0.3.0" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -9,5 +9,4 @@ edition = "2018" clipboard-win = "4.2.1" winapi = {version = "0.3.9", features = ["winuser", "std", "impl-default"]} error-code = "2.3.0" -clap = "3.0.0-beta.4" -rayon = "1.5.1" \ No newline at end of file +clap = "3.0.0-beta.4" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 53291a9..18091b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,14 +177,32 @@ pub fn run(opts: Opts) { compare_data(&cb_data, last_update, SIMILARITY_THRESHOLD) }) .unwrap_or(ComparisonResult::Different); + #[cfg(debug_assertions)] + { + if let Some(cb_data) = last_internal_update.as_ref() { + println!("prev_item: {}", get_cb_text(cb_data)); + } + + if let Some(cb_data) = cb_history.front() { + println!("current_item: {}", get_cb_text(cb_data)); + } + + println!("New item: {}", get_cb_text(&cb_data)); + } match (prev_item_similarity, current_item_similarity) { (_, ComparisonResult::Same) | (ComparisonResult::Same, _) => {} (_, ComparisonResult::Similar) | (ComparisonResult::Similar, _) => { - *cb_history.front_mut().unwrap() = cb_data; - last_internal_update = None; + #[cfg(debug_assertions)] + println!("Updating last element: {}", get_cb_text(&cb_data)); + if let Some(cb_history_front) = cb_history.front_mut() { + *cb_history_front = cb_data; + last_internal_update = None; + } } (ComparisonResult::Different, ComparisonResult::Different) => { + #[cfg(debug_assertions)] + println!("Appending to history: {}", get_cb_text(&cb_data)); cb_history.push_front(cb_data); cb_history.truncate(opts.max_history); last_internal_update = None; @@ -197,6 +215,8 @@ pub fn run(opts: Opts) { winuser::WM_HOTKEY => { if lp_msg.wParam == 1 { /*Ctrl + Shift + V*/ + #[cfg(debug_assertions)] + dbg!("Ctrl+Shift+V"); fn old_state(v_key: i32) -> u32 { match is_key_pressed(v_key) { Ok(false) => winuser::KEYEVENTF_KEYUP, @@ -204,9 +224,6 @@ pub fn run(opts: Opts) { } } - let old_control = old_state(winuser::VK_CONTROL); - let old_v = old_state('V' as i32); - match trigger_keys( &[ winuser::VK_SHIFT as u16, @@ -218,19 +235,11 @@ pub fn run(opts: Opts) { ], &[ winuser::KEYEVENTF_KEYUP, - if old_control == 0 { - winuser::KEYEVENTF_KEYUP - } else { - 0 - }, - if old_v == 0 { - winuser::KEYEVENTF_KEYUP - } else { - 0 - }, - old_control, - old_v, - old_state(winuser::VK_SHIFT), + winuser::KEYEVENTF_KEYUP, + winuser::KEYEVENTF_KEYUP, + 0, + 0, + 0, ], ) { Ok(_) => {