mirror of
https://github.com/Noratrieb/clippyboard.git
synced 2026-01-14 09:55:04 +01:00
split into crates
This commit is contained in:
parent
06b5244638
commit
14e5170f4f
13 changed files with 112 additions and 67 deletions
35
Cargo.lock
generated
35
Cargo.lock
generated
|
|
@ -610,23 +610,52 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "clippyboard"
|
||||
name = "clippyboard-clear"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clippyboard-shared",
|
||||
"eyre",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clippyboard-daemon"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ciborium",
|
||||
"clippyboard-shared",
|
||||
"ctrlc",
|
||||
"dirs",
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
"eyre",
|
||||
"rustix 1.1.2",
|
||||
"serde",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clippyboard-select"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ciborium",
|
||||
"clippyboard-shared",
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
"eyre",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clippyboard-shared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"eyre",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.12.0"
|
||||
|
|
|
|||
29
Cargo.toml
29
Cargo.toml
|
|
@ -1,30 +1,13 @@
|
|||
[package]
|
||||
name = "clippyboard"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = [
|
||||
"clippyboard-*"
|
||||
]
|
||||
|
||||
[[bin]]
|
||||
name = "clippyboard-daemon"
|
||||
|
||||
[[bin]]
|
||||
name = "clippyboard-select"
|
||||
|
||||
[[bin]]
|
||||
name = "clippyboard-clear"
|
||||
|
||||
[dependencies]
|
||||
[workspace.dependencies]
|
||||
ciborium = "0.2.2"
|
||||
ctrlc = "3.5.0"
|
||||
dirs = "6.0.0"
|
||||
eframe = "0.32.2"
|
||||
egui_extras = { version = "0.32.2", features = ["image"] }
|
||||
eyre = "0.6.12"
|
||||
rustix = "1.1.2"
|
||||
serde = "1.0.219"
|
||||
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"
|
||||
|
|
|
|||
8
clippyboard-clear/Cargo.toml
Normal file
8
clippyboard-clear/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "clippyboard-clear"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clippyboard-shared = { path = "../clippyboard-shared" }
|
||||
eyre = "0.6.12"
|
||||
|
|
@ -3,7 +3,7 @@ use std::{io::Write, os::unix::net::UnixStream};
|
|||
use eyre::Context;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
let socket_path = clippyboard::socket_path()?;
|
||||
let socket_path = clippyboard_shared::socket_path()?;
|
||||
|
||||
let mut socket = UnixStream::connect(&socket_path).wrap_err_with(|| {
|
||||
format!(
|
||||
|
|
@ -12,7 +12,7 @@ fn main() -> eyre::Result<()> {
|
|||
)
|
||||
})?;
|
||||
socket
|
||||
.write_all(&[clippyboard::MESSAGE_CLEAR])
|
||||
.write_all(&[clippyboard_shared::MESSAGE_CLEAR])
|
||||
.wrap_err("writing clear message to socket")?;
|
||||
|
||||
Ok(())
|
||||
18
clippyboard-daemon/Cargo.toml
Normal file
18
clippyboard-daemon/Cargo.toml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "clippyboard-daemon"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clippyboard-shared = { path = "../clippyboard-shared" }
|
||||
ciborium = "0.2.2"
|
||||
ctrlc = "3.5.0"
|
||||
dirs = "6.0.0"
|
||||
eyre = "0.6.12"
|
||||
rustix = "1.1.2"
|
||||
serde = "1.0.219"
|
||||
tracing = { version = "0.1.41", features = ["attributes"] }
|
||||
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
||||
wayland-backend = { version = "0.3.11", features = ["client_system"] }
|
||||
wayland-client = "0.31.11"
|
||||
wayland-protocols = { version = "0.32.9", features = ["staging", "client"] }
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
use super::HistoryItem;
|
||||
use super::MAX_ENTRY_SIZE;
|
||||
use eframe::egui::ahash::HashSet;
|
||||
use clippyboard_shared::HistoryItem;
|
||||
use eyre::Context;
|
||||
use eyre::ContextCompat;
|
||||
use eyre::bail;
|
||||
|
|
@ -8,6 +6,7 @@ use rustix::event::PollFd;
|
|||
use rustix::event::PollFlags;
|
||||
use rustix::fs::OFlags;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::convert::Infallible;
|
||||
use std::io;
|
||||
use std::io::ErrorKind;
|
||||
|
|
@ -39,6 +38,9 @@ use wayland_protocols::ext::data_control::v1::client::ext_data_control_offer_v1:
|
|||
use wayland_protocols::ext::data_control::v1::client::ext_data_control_source_v1;
|
||||
use wayland_protocols::ext::data_control::v1::client::ext_data_control_source_v1::ExtDataControlSourceV1;
|
||||
|
||||
const MAX_ENTRY_SIZE: u64 = 50_000_000;
|
||||
const MAX_HISTORY_BYTE_SIZE: usize = 100_000_000;
|
||||
|
||||
const MIME_TYPES: &[&str] = &["text/plain", "image/png", "image/jpg"];
|
||||
|
||||
struct SharedState {
|
||||
|
|
@ -372,16 +374,16 @@ fn handle_peer(mut peer: UnixStream, shared_state: &SharedState) -> eyre::Result
|
|||
return Ok(());
|
||||
};
|
||||
match request[0] {
|
||||
super::MESSAGE_READ => {
|
||||
clippyboard_shared::MESSAGE_READ => {
|
||||
let items = shared_state.items.lock().unwrap();
|
||||
|
||||
ciborium::into_writer(items.as_slice(), BufWriter::new(peer))
|
||||
.wrap_err("writing items to socket")?;
|
||||
}
|
||||
super::MESSAGE_COPY => {
|
||||
clippyboard_shared::MESSAGE_COPY => {
|
||||
handle_copy_message(peer, shared_state).wrap_err("handling copy message")?;
|
||||
}
|
||||
super::MESSAGE_CLEAR => {
|
||||
clippyboard_shared::MESSAGE_CLEAR => {
|
||||
handle_clear_message(&shared_state)?;
|
||||
info!("Cleared history and clipboard");
|
||||
}
|
||||
|
|
@ -479,14 +481,16 @@ fn read_fd_into_history(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn main(socket_path: &PathBuf) -> eyre::Result<()> {
|
||||
fn main() -> eyre::Result<()> {
|
||||
let socket_path = clippyboard_shared::socket_path()?;
|
||||
|
||||
let socket_path2 = socket_path.clone();
|
||||
let _ = ctrlc::set_handler(move || {
|
||||
cleanup(&socket_path2);
|
||||
std::process::exit(130); // sigint
|
||||
});
|
||||
|
||||
let Err(err) = main_inner(socket_path);
|
||||
let Err(err) = main_inner(&socket_path);
|
||||
|
||||
if let Some(ioerr) = err.downcast_ref::<io::Error>()
|
||||
&& ioerr.kind() == ErrorKind::AddrInUse
|
||||
|
|
@ -495,7 +499,7 @@ pub fn main(socket_path: &PathBuf) -> eyre::Result<()> {
|
|||
return Err(err);
|
||||
}
|
||||
|
||||
cleanup(socket_path);
|
||||
cleanup(&socket_path);
|
||||
Err(err)
|
||||
}
|
||||
|
||||
12
clippyboard-select/Cargo.toml
Normal file
12
clippyboard-select/Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "clippyboard-select"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clippyboard-shared = { path = "../clippyboard-shared" }
|
||||
ciborium.workspace = true
|
||||
eframe = "0.32.2"
|
||||
egui_extras = { version = "0.32.2", features = ["image"] }
|
||||
eyre.workspace = true
|
||||
serde.workspace = true
|
||||
|
|
@ -1,19 +1,14 @@
|
|||
use clippyboard_shared::HistoryItem;
|
||||
use clippyboard_shared::MESSAGE_COPY;
|
||||
use clippyboard_shared::MESSAGE_READ;
|
||||
use eframe::egui;
|
||||
use eyre::Context;
|
||||
|
||||
use crate::MESSAGE_READ;
|
||||
|
||||
use super::MESSAGE_COPY;
|
||||
|
||||
use std::{
|
||||
io::{BufReader, Write},
|
||||
os::unix::net::UnixStream,
|
||||
path::Path,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use super::HistoryItem;
|
||||
|
||||
pub(crate) struct App {
|
||||
pub(crate) items: Vec<HistoryItem>,
|
||||
pub(crate) selected_idx: usize,
|
||||
|
|
@ -112,7 +107,9 @@ impl eframe::App for App {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn main(socket_path: &Path) -> eyre::Result<()> {
|
||||
pub fn main() -> eyre::Result<()> {
|
||||
let socket_path = clippyboard_shared::socket_path()?;
|
||||
|
||||
let mut socket = UnixStream::connect(&socket_path).wrap_err_with(|| {
|
||||
format!(
|
||||
"connecting to socket at {}. is the daemon running?",
|
||||
9
clippyboard-shared/Cargo.toml
Normal file
9
clippyboard-shared/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "clippyboard-shared"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0.219"
|
||||
dirs = "6.0.0"
|
||||
eyre = "0.6.12"
|
||||
|
|
@ -1,23 +1,18 @@
|
|||
pub mod daemon;
|
||||
pub mod display;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use eyre::OptionExt;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
const MAX_ENTRY_SIZE: u64 = 50_000_000;
|
||||
const MAX_HISTORY_BYTE_SIZE: usize = 100_000_000;
|
||||
|
||||
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
||||
struct HistoryItem {
|
||||
id: u64,
|
||||
mime: String,
|
||||
pub struct HistoryItem {
|
||||
pub id: u64,
|
||||
pub mime: String,
|
||||
#[serde(
|
||||
deserialize_with = "deserialize_data",
|
||||
serialize_with = "serialize_data"
|
||||
)]
|
||||
data: Arc<[u8]>,
|
||||
created_time: u64,
|
||||
pub data: Arc<[u8]>,
|
||||
pub created_time: u64,
|
||||
}
|
||||
|
||||
fn deserialize_data<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Arc<[u8]>, D::Error> {
|
||||
|
|
@ -25,8 +25,6 @@
|
|||
--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;
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
fn main() -> Result<(), eyre::Error> {
|
||||
let socket_path: std::path::PathBuf = clippyboard::socket_path()?;
|
||||
clippyboard::daemon::main(&socket_path)
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
fn main() -> Result<(), eyre::Error> {
|
||||
let socket_path = clippyboard::socket_path()?;
|
||||
clippyboard::display::main(&socket_path)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue