mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-15 03:07:02 +05:30
feat: drop clipboard-master
dependency
It's just a busy loop this thing is completely unnecessary
This commit is contained in:
parent
32bc894f0a
commit
c698b9d509
4 changed files with 12 additions and 87 deletions
55
Cargo.lock
generated
55
Cargo.lock
generated
|
@ -115,20 +115,6 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clipboard-master"
|
|
||||||
version = "3.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "459887701008d8ee21f8de7f45f0f0707417c7eea3311973f6e67222bd686b7a"
|
|
||||||
dependencies = [
|
|
||||||
"objc",
|
|
||||||
"objc-foundation",
|
|
||||||
"objc_id",
|
|
||||||
"winapi",
|
|
||||||
"windows-win",
|
|
||||||
"x11-clipboard 0.5.3",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clipboard-substitutor"
|
name = "clipboard-substitutor"
|
||||||
version = "0.7.6"
|
version = "0.7.6"
|
||||||
|
@ -136,7 +122,6 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"argv",
|
"argv",
|
||||||
"assay",
|
"assay",
|
||||||
"clipboard-master",
|
|
||||||
"copypasta",
|
"copypasta",
|
||||||
"dirs",
|
"dirs",
|
||||||
"regex",
|
"regex",
|
||||||
|
@ -168,7 +153,7 @@ dependencies = [
|
||||||
"objc",
|
"objc",
|
||||||
"objc-foundation",
|
"objc-foundation",
|
||||||
"objc_id",
|
"objc_id",
|
||||||
"x11-clipboard 0.8.1",
|
"x11-clipboard",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -477,15 +462,6 @@ version = "1.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quick-xml"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.33"
|
version = "1.0.33"
|
||||||
|
@ -922,15 +898,6 @@ dependencies = [
|
||||||
"windows_x86_64_msvc 0.52.0",
|
"windows_x86_64_msvc 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-win"
|
|
||||||
version = "2.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8d4243ec23afe4e9b4e668b3c0a0e973f1b8265f6a46223cfcbc16fd267480c0"
|
|
||||||
dependencies = [
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_gnullvm"
|
name = "windows_aarch64_gnullvm"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
|
@ -1024,15 +991,6 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "x11-clipboard"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "473068b7b80ac86a18328824f1054e5e007898c47b5bbc281bd7abe32bc3653c"
|
|
||||||
dependencies = [
|
|
||||||
"xcb",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "x11-clipboard"
|
name = "x11-clipboard"
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
|
@ -1064,17 +1022,6 @@ dependencies = [
|
||||||
"nix",
|
"nix",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xcb"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
"quick-xml",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yansi"
|
name = "yansi"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
|
|
@ -15,7 +15,6 @@ include = ["src/**/*", "LICENSE-*", "README.md"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.76"
|
anyhow = "1.0.76"
|
||||||
argv = "0.1.10"
|
argv = "0.1.10"
|
||||||
clipboard-master = "3.1.3"
|
|
||||||
copypasta = { version = "0.10.0", default-features = false, features = ["x11"] }
|
copypasta = { version = "0.10.0", default-features = false, features = ["x11"] }
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
regex = "1.10.2"
|
regex = "1.10.2"
|
||||||
|
|
|
@ -1,46 +1,26 @@
|
||||||
use std::io;
|
use crate::config::{Act, Match, Replacements};
|
||||||
use std::ops::Not;
|
use anyhow::Result;
|
||||||
|
|
||||||
use clipboard_master::{CallbackResult, ClipboardHandler, Master};
|
|
||||||
use copypasta::{ClipboardContext, ClipboardProvider};
|
use copypasta::{ClipboardContext, ClipboardProvider};
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
use crate::config::{Act, Match, Replacements};
|
pub fn monitor(config: Replacements) -> Result<()> {
|
||||||
|
loop {
|
||||||
struct Handler {
|
let mut clipboard =
|
||||||
ctx: ClipboardContext,
|
ClipboardContext::new().expect("Failed to get clipboard");
|
||||||
config: Replacements,
|
if let Ok(contents) = clipboard.get_contents() {
|
||||||
}
|
if let Some(subst) = config
|
||||||
|
|
||||||
impl ClipboardHandler for Handler {
|
|
||||||
fn on_clipboard_change(&mut self) -> CallbackResult {
|
|
||||||
if let Ok(contents) = self.ctx.get_contents() {
|
|
||||||
if let Some(subst) = self
|
|
||||||
.config
|
|
||||||
.substitutors
|
.substitutors
|
||||||
.iter()
|
.iter()
|
||||||
.find(|subst| subst.matcher.check_match(&contents))
|
.find(|subst| subst.matcher.check_match(&contents))
|
||||||
{
|
{
|
||||||
if subst.name.is_empty().not() {
|
if !subst.name.is_empty() {
|
||||||
debug!(?subst.name, ?contents);
|
debug!(?subst.name, ?contents);
|
||||||
}
|
}
|
||||||
let result = subst.action.apply_action(&contents);
|
let result = subst.action.apply_action(&contents);
|
||||||
if let Err(e) = self.ctx.set_contents(result) {
|
if let Err(e) = clipboard.set_contents(result) {
|
||||||
error!("{}", e);
|
error!("{}", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
CallbackResult::Next
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_clipboard_error(&mut self, error: io::Error) -> CallbackResult {
|
|
||||||
error!("Error: {}", error);
|
|
||||||
CallbackResult::Next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn monitor(config: Replacements) {
|
|
||||||
let ctx = ClipboardContext::new().expect("Failed to acquire clipboard");
|
|
||||||
let handler = Handler { ctx, config };
|
|
||||||
let _master = Master::new(handler).run();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,7 @@ fn main() -> Result<()> {
|
||||||
std::fs::read_to_string(config_path.as_path()).unwrap_or_default();
|
std::fs::read_to_string(config_path.as_path()).unwrap_or_default();
|
||||||
let config: Replacements = toml::from_str(&config_str)?;
|
let config: Replacements = toml::from_str(&config_str)?;
|
||||||
config.validate()?;
|
config.validate()?;
|
||||||
monitor(config);
|
monitor(config)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_version_arg() -> bool {
|
fn check_for_version_arg() -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue