mirror of
https://github.com/Noratrieb/clippyboard.git
synced 2026-01-14 18:05: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]]
|
[[package]]
|
||||||
name = "clippyboard"
|
name = "clippyboard-clear"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"clippyboard-shared",
|
||||||
|
"eyre",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clippyboard-daemon"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ciborium",
|
"ciborium",
|
||||||
|
"clippyboard-shared",
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
"dirs",
|
"dirs",
|
||||||
"eframe",
|
|
||||||
"egui_extras",
|
|
||||||
"eyre",
|
"eyre",
|
||||||
"rustix 1.1.2",
|
"rustix 1.1.2",
|
||||||
"serde",
|
"serde",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"wayland-backend",
|
||||||
"wayland-client",
|
"wayland-client",
|
||||||
"wayland-protocols",
|
"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]]
|
[[package]]
|
||||||
name = "codespan-reporting"
|
name = "codespan-reporting"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
|
|
|
||||||
29
Cargo.toml
29
Cargo.toml
|
|
@ -1,30 +1,13 @@
|
||||||
[package]
|
[workspace]
|
||||||
name = "clippyboard"
|
resolver = "3"
|
||||||
version = "0.1.0"
|
members = [
|
||||||
edition = "2024"
|
"clippyboard-*"
|
||||||
|
]
|
||||||
|
|
||||||
[[bin]]
|
[workspace.dependencies]
|
||||||
name = "clippyboard-daemon"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "clippyboard-select"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "clippyboard-clear"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
ciborium = "0.2.2"
|
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"
|
eyre = "0.6.12"
|
||||||
rustix = "1.1.2"
|
|
||||||
serde = "1.0.219"
|
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]
|
[profile.release]
|
||||||
lto = "thin"
|
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;
|
use eyre::Context;
|
||||||
|
|
||||||
fn main() -> eyre::Result<()> {
|
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(|| {
|
let mut socket = UnixStream::connect(&socket_path).wrap_err_with(|| {
|
||||||
format!(
|
format!(
|
||||||
|
|
@ -12,7 +12,7 @@ fn main() -> eyre::Result<()> {
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
socket
|
socket
|
||||||
.write_all(&[clippyboard::MESSAGE_CLEAR])
|
.write_all(&[clippyboard_shared::MESSAGE_CLEAR])
|
||||||
.wrap_err("writing clear message to socket")?;
|
.wrap_err("writing clear message to socket")?;
|
||||||
|
|
||||||
Ok(())
|
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 clippyboard_shared::HistoryItem;
|
||||||
use super::MAX_ENTRY_SIZE;
|
|
||||||
use eframe::egui::ahash::HashSet;
|
|
||||||
use eyre::Context;
|
use eyre::Context;
|
||||||
use eyre::ContextCompat;
|
use eyre::ContextCompat;
|
||||||
use eyre::bail;
|
use eyre::bail;
|
||||||
|
|
@ -8,6 +6,7 @@ use rustix::event::PollFd;
|
||||||
use rustix::event::PollFlags;
|
use rustix::event::PollFlags;
|
||||||
use rustix::fs::OFlags;
|
use rustix::fs::OFlags;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::ErrorKind;
|
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;
|
||||||
use wayland_protocols::ext::data_control::v1::client::ext_data_control_source_v1::ExtDataControlSourceV1;
|
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"];
|
const MIME_TYPES: &[&str] = &["text/plain", "image/png", "image/jpg"];
|
||||||
|
|
||||||
struct SharedState {
|
struct SharedState {
|
||||||
|
|
@ -372,16 +374,16 @@ fn handle_peer(mut peer: UnixStream, shared_state: &SharedState) -> eyre::Result
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
match request[0] {
|
match request[0] {
|
||||||
super::MESSAGE_READ => {
|
clippyboard_shared::MESSAGE_READ => {
|
||||||
let items = shared_state.items.lock().unwrap();
|
let items = shared_state.items.lock().unwrap();
|
||||||
|
|
||||||
ciborium::into_writer(items.as_slice(), BufWriter::new(peer))
|
ciborium::into_writer(items.as_slice(), BufWriter::new(peer))
|
||||||
.wrap_err("writing items to socket")?;
|
.wrap_err("writing items to socket")?;
|
||||||
}
|
}
|
||||||
super::MESSAGE_COPY => {
|
clippyboard_shared::MESSAGE_COPY => {
|
||||||
handle_copy_message(peer, shared_state).wrap_err("handling copy message")?;
|
handle_copy_message(peer, shared_state).wrap_err("handling copy message")?;
|
||||||
}
|
}
|
||||||
super::MESSAGE_CLEAR => {
|
clippyboard_shared::MESSAGE_CLEAR => {
|
||||||
handle_clear_message(&shared_state)?;
|
handle_clear_message(&shared_state)?;
|
||||||
info!("Cleared history and clipboard");
|
info!("Cleared history and clipboard");
|
||||||
}
|
}
|
||||||
|
|
@ -479,14 +481,16 @@ fn read_fd_into_history(
|
||||||
Ok(())
|
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 socket_path2 = socket_path.clone();
|
||||||
let _ = ctrlc::set_handler(move || {
|
let _ = ctrlc::set_handler(move || {
|
||||||
cleanup(&socket_path2);
|
cleanup(&socket_path2);
|
||||||
std::process::exit(130); // sigint
|
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>()
|
if let Some(ioerr) = err.downcast_ref::<io::Error>()
|
||||||
&& ioerr.kind() == ErrorKind::AddrInUse
|
&& ioerr.kind() == ErrorKind::AddrInUse
|
||||||
|
|
@ -495,7 +499,7 @@ pub fn main(socket_path: &PathBuf) -> eyre::Result<()> {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup(socket_path);
|
cleanup(&socket_path);
|
||||||
Err(err)
|
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 eframe::egui;
|
||||||
use eyre::Context;
|
use eyre::Context;
|
||||||
|
|
||||||
use crate::MESSAGE_READ;
|
|
||||||
|
|
||||||
use super::MESSAGE_COPY;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::{BufReader, Write},
|
io::{BufReader, Write},
|
||||||
os::unix::net::UnixStream,
|
os::unix::net::UnixStream,
|
||||||
path::Path,
|
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::HistoryItem;
|
|
||||||
|
|
||||||
pub(crate) struct App {
|
pub(crate) struct App {
|
||||||
pub(crate) items: Vec<HistoryItem>,
|
pub(crate) items: Vec<HistoryItem>,
|
||||||
pub(crate) selected_idx: usize,
|
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(|| {
|
let mut socket = UnixStream::connect(&socket_path).wrap_err_with(|| {
|
||||||
format!(
|
format!(
|
||||||
"connecting to socket at {}. is the daemon running?",
|
"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;
|
use std::{path::PathBuf, sync::Arc};
|
||||||
pub mod display;
|
|
||||||
|
|
||||||
use eyre::OptionExt;
|
use eyre::OptionExt;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
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)]
|
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
||||||
struct HistoryItem {
|
pub struct HistoryItem {
|
||||||
id: u64,
|
pub id: u64,
|
||||||
mime: String,
|
pub mime: String,
|
||||||
#[serde(
|
#[serde(
|
||||||
deserialize_with = "deserialize_data",
|
deserialize_with = "deserialize_data",
|
||||||
serialize_with = "serialize_data"
|
serialize_with = "serialize_data"
|
||||||
)]
|
)]
|
||||||
data: Arc<[u8]>,
|
pub data: Arc<[u8]>,
|
||||||
created_time: u64,
|
pub created_time: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_data<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Arc<[u8]>, D::Error> {
|
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}
|
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
|
||||||
wrapProgram $out/bin/clippyboard-daemon \
|
wrapProgram $out/bin/clippyboard-daemon \
|
||||||
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
|
--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;
|
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