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
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"
|
||||
40
clippyboard-shared/src/lib.rs
Normal file
40
clippyboard-shared/src/lib.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use eyre::OptionExt;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
||||
pub struct HistoryItem {
|
||||
pub id: u64,
|
||||
pub mime: String,
|
||||
#[serde(
|
||||
deserialize_with = "deserialize_data",
|
||||
serialize_with = "serialize_data"
|
||||
)]
|
||||
pub data: Arc<[u8]>,
|
||||
pub created_time: u64,
|
||||
}
|
||||
|
||||
fn deserialize_data<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Arc<[u8]>, D::Error> {
|
||||
Box::<[u8]>::deserialize(deserializer).map(Into::into)
|
||||
}
|
||||
|
||||
fn serialize_data<S: Serializer>(data: &Arc<[u8]>, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
let data: &[u8] = data;
|
||||
data.serialize(serializer)
|
||||
}
|
||||
|
||||
pub const MESSAGE_READ: u8 = 1;
|
||||
/// Argument: One u64-bit LE value, the ID
|
||||
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") {
|
||||
return Ok(path.into());
|
||||
}
|
||||
|
||||
Ok(dirs::runtime_dir()
|
||||
.ok_or_eyre("missing XDG_RUNTIME_DIR")?
|
||||
.join("clippyboard.sock"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue