mirror of
https://github.com/Noratrieb/clippyboard.git
synced 2026-01-14 09:55:04 +01:00
Add clippyboard-clear command
This commit is contained in:
parent
a2bfdf331b
commit
0779094712
5 changed files with 34 additions and 2 deletions
|
|
@ -9,6 +9,9 @@ name = "clippyboard-daemon"
|
|||
[[bin]]
|
||||
name = "clippyboard-select"
|
||||
|
||||
[[bin]]
|
||||
name = "clippyboard-clear"
|
||||
|
||||
[dependencies]
|
||||
ciborium = "0.2.2"
|
||||
ctrlc = "3.5.0"
|
||||
|
|
@ -22,3 +25,6 @@ tracing = { version = "0.1.41", features = ["attributes"] }
|
|||
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
||||
wayland-client = "0.31.11"
|
||||
wayland-protocols = { version = "0.32.9", features = ["staging"] }
|
||||
|
||||
[profile.release]
|
||||
lto = "thin"
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@
|
|||
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
|
||||
wrapProgram $out/bin/clippyboard-daemon \
|
||||
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
|
||||
wrapProgram $out/bin/clippyboard-clear \
|
||||
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
|
||||
'';
|
||||
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
|
|
|
|||
19
src/bin/clippyboard-clear.rs
Normal file
19
src/bin/clippyboard-clear.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use std::{io::Write, os::unix::net::UnixStream};
|
||||
|
||||
use eyre::Context;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
let socket_path = clippyboard::socket_path()?;
|
||||
|
||||
let mut socket = UnixStream::connect(&socket_path).wrap_err_with(|| {
|
||||
format!(
|
||||
"connecting to socket at {}. is the daemon running?",
|
||||
socket_path.display()
|
||||
)
|
||||
})?;
|
||||
socket
|
||||
.write_all(&[clippyboard::MESSAGE_CLEAR])
|
||||
.wrap_err("writing clear message to socket")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -375,6 +375,10 @@ fn handle_peer(mut peer: UnixStream, shared_state: &SharedState) -> eyre::Result
|
|||
super::MESSAGE_COPY => {
|
||||
handle_copy_message(peer, shared_state).wrap_err("handling copy message")?;
|
||||
}
|
||||
super::MESSAGE_CLEAR => {
|
||||
shared_state.items.lock().unwrap().clear();
|
||||
info!("Cleared history");
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ fn serialize_data<S: Serializer>(data: &Arc<[u8]>, serializer: S) -> Result<S::O
|
|||
data.serialize(serializer)
|
||||
}
|
||||
|
||||
const MESSAGE_READ: u8 = 1;
|
||||
pub const MESSAGE_READ: u8 = 1;
|
||||
/// Argument: One u64-bit LE value, the ID
|
||||
const MESSAGE_COPY: u8 = 2;
|
||||
pub const MESSAGE_COPY: u8 = 2;
|
||||
pub const MESSAGE_CLEAR: u8 = 3;
|
||||
|
||||
pub fn socket_path() -> eyre::Result<PathBuf> {
|
||||
if let Some(path) = std::env::var_os("CLIPPYBOARD_SOCKET") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue