Skip to content

Commit

Permalink
Merge pull request #202 from xrelkd/release/0.15.0
Browse files Browse the repository at this point in the history
Release `0.15.0`
  • Loading branch information
xrelkd authored Dec 15, 2023
2 parents 00d332f + 1882849 commit 7f77632
Show file tree
Hide file tree
Showing 36 changed files with 682 additions and 483 deletions.
216 changes: 120 additions & 96 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.14.0"
version = "0.15.0"
authors = ["xrelkd <46590321+xrelkd@users.noreply.github.com>"]
homepage = "https://github.com/xrelkd/clipcat"
repository = "https://github.com/xrelkd/clipcat"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ cd ~/bin

# download and extract clipcat to ~/bin/
# NOTE: replace the version with the version you want to install
export CLIPCAT_VERSION=v0.14.0
export CLIPCAT_VERSION=v0.15.0

# NOTE: the architecture of your machine,
# available values are `x86_64-unknown-linux-musl`, `armv7-unknown-linux-musleabihf`, `aarch64-unknown-linux-musl`
Expand Down
2 changes: 2 additions & 0 deletions clipcat-menu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ categories.workspace = true
keywords.workspace = true

[dependencies]
mimalloc = "0.1"

tracing = "0.1"
tracing-journald = "0.3"
tracing-subscriber = "0.3"
Expand Down
5 changes: 5 additions & 0 deletions clipcat-menu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ mod config;
mod error;
mod finder;

use mimalloc::MiMalloc;

use self::cli::Cli;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

fn main() {
if let Err(err) = Cli::default().run() {
eprintln!("Error: {err}");
Expand Down
2 changes: 2 additions & 0 deletions clipcat-notify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ categories.workspace = true
keywords.workspace = true

[dependencies]
mimalloc = "0.1"

serde = { version = "1", features = ["derive"] }
serde_json = "1"

Expand Down
34 changes: 28 additions & 6 deletions clipcat-notify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ use std::{io::Write, sync::Arc};

use clap::{CommandFactory, Parser, Subcommand};
use clipcat_base::{ClipFilter, ClipboardKind};
use mimalloc::MiMalloc;
use serde::Serialize;
use snafu::ResultExt;
use time::OffsetDateTime;
use tokio::runtime::Runtime;

use self::error::Error;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

#[derive(Parser)]
#[clap(name = clipcat_base::NOTIFY_PROGRAM_NAME, author, version, about, long_about = None)]
struct Cli {
Expand Down Expand Up @@ -56,15 +60,33 @@ impl Cli {
let enable_primary = !self.no_primary;
let enable_secondary = !self.no_secondary;

if !enable_clipboard && !enable_primary && !enable_secondary {
return Err(Error::ListenToNothing);
}
let clipboard_kinds = {
let mut clipboard_kinds = Vec::with_capacity(ClipboardKind::MAX_LENGTH);
if enable_clipboard {
clipboard_kinds.push(ClipboardKind::Clipboard);
}
if enable_primary {
clipboard_kinds.push(ClipboardKind::Primary);
}
if enable_secondary {
clipboard_kinds.push(ClipboardKind::Secondary);
}

if clipboard_kinds.is_empty() {
return Err(Error::ListenToNothing);
}

clipboard_kinds
};

Runtime::new().context(error::InitializeTokioRuntimeSnafu)?.block_on(
async move {
let backend =
clipcat_server::backend::new(&Arc::new(ClipFilter::default()), &[])
.context(error::InitializeClipboardBackendSnafu)?;
let backend = clipcat_server::backend::new(
clipboard_kinds,
&Arc::new(ClipFilter::default()),
&[],
)
.context(error::InitializeClipboardBackendSnafu)?;
let mut subscriber =
backend.subscribe().context(error::SubscribeClipboardSnafu)?;

Expand Down
2 changes: 2 additions & 0 deletions clipcatctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ categories.workspace = true
keywords.workspace = true

[dependencies]
mimalloc = "0.1"

tracing = "0.1"
tracing-journald = "0.3"
tracing-subscriber = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion clipcatctl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Cli {
}
Some(Commands::Get { id }) => {
let data = if let Some(id) = id {
client.get(id).await?.printable_data(None)
client.get(id).await?.preview_information(None)
} else {
client
.list(PREVIEW_LENGTH)
Expand Down
5 changes: 5 additions & 0 deletions clipcatctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ mod cli;
mod config;
mod error;

use mimalloc::MiMalloc;

use self::cli::Cli;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

fn main() {
match Cli::default().run() {
Ok(exit_code) => {
Expand Down
3 changes: 3 additions & 0 deletions clipcatd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ categories.workspace = true
keywords.workspace = true

[dependencies]
mimalloc = "0.1"

tracing = "0.1"
tracing-journald = "0.3"
tracing-subscriber = "0.3"
Expand All @@ -31,6 +33,7 @@ linicon = "2"
mime = "0.3"
simdutf8 = "0.1"
snafu = "0.7"
time = { version = "0.3", features = ["formatting", "macros"] }

clipcat-base = { path = "../crates/base" }
clipcat-cli = { path = "../crates/cli" }
Expand Down
11 changes: 10 additions & 1 deletion clipcatd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
use directories::BaseDirs;
use serde::{Deserialize, Serialize};
use snafu::{ResultExt, Snafu};
use time::OffsetDateTime;

const DEFAULT_ICON_NAME: &str = "accessories-clipboard";

Expand Down Expand Up @@ -53,6 +54,9 @@ pub struct WatcherConfig {
#[serde(default)]
pub enable_primary: bool,

#[serde(default = "WatcherConfig::default_enable_secondary")]
pub enable_secondary: bool,

#[serde(default = "WatcherConfig::default_sensitive_x11_atoms")]
pub sensitive_x11_atoms: HashSet<String>,

Expand All @@ -78,6 +82,7 @@ impl From<WatcherConfig> for clipcat_server::ClipboardWatcherOptions {
load_current,
enable_clipboard,
enable_primary,
enable_secondary,
capture_image,
filter_text_min_length,
filter_text_max_length,
Expand All @@ -90,6 +95,7 @@ impl From<WatcherConfig> for clipcat_server::ClipboardWatcherOptions {
load_current,
enable_clipboard,
enable_primary,
enable_secondary,
capture_image,
filter_text_min_length,
filter_text_max_length,
Expand All @@ -110,6 +116,8 @@ impl WatcherConfig {
5 * (1 << 20)
}

pub const fn default_enable_secondary() -> bool { false }

pub fn default_sensitive_x11_atoms() -> HashSet<String> {
HashSet::from(["x-kde-passwordManagerHint".to_string()])
}
Expand Down Expand Up @@ -206,7 +214,7 @@ impl SnippetConfig {
&data,
&mime::TEXT_PLAIN_UTF_8,
clipcat_base::ClipboardKind::Clipboard,
None,
Some(OffsetDateTime::UNIX_EPOCH),
)
.ok()
} else {
Expand Down Expand Up @@ -237,6 +245,7 @@ impl Default for WatcherConfig {
load_current: true,
enable_clipboard: true,
enable_primary: true,
enable_secondary: Self::default_enable_secondary(),
capture_image: true,
filter_text_min_length: Self::default_filter_text_min_length(),
filter_text_max_length: Self::default_filter_text_max_length(),
Expand Down
5 changes: 5 additions & 0 deletions clipcatd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ mod config;
mod error;
mod pid_file;

use mimalloc::MiMalloc;

use self::{command::Cli, error::CommandError};

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

fn main() {
if let Err(err) = Cli::default().run() {
eprintln!("Error: {err}");
Expand Down
57 changes: 12 additions & 45 deletions crates/base/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
cmp::Ordering,
collections::hash_map::DefaultHasher,
fmt,
hash::{Hash, Hasher},
};
Expand All @@ -14,8 +13,6 @@ use crate::{ClipboardContent, ClipboardKind};

#[derive(Clone, Debug, Eq)]
pub struct Entry {
id: u64,

content: ClipboardContent,

clipboard_kind: ClipboardKind,
Expand Down Expand Up @@ -65,13 +62,9 @@ impl Entry {
};

let sha256_digest = compute_sha256_digest(&content);
Ok(Self {
id: Self::compute_id(&content),
content,
clipboard_kind,
timestamp: timestamp.unwrap_or_else(OffsetDateTime::now_utc),
sha256_digest,
})
let timestamp = timestamp.unwrap_or_else(OffsetDateTime::now_utc);

Ok(Self { content, clipboard_kind, timestamp, sha256_digest })
}

#[inline]
Expand All @@ -88,7 +81,6 @@ impl Entry {
) -> Self {
let sha256_digest = compute_sha256_digest(&content);
Self {
id: Self::compute_id(&content),
content,
clipboard_kind,
timestamp: timestamp.unwrap_or_else(OffsetDateTime::now_utc),
Expand All @@ -98,15 +90,7 @@ impl Entry {

#[inline]
#[must_use]
pub fn compute_id(data: &ClipboardContent) -> u64 {
let mut s = DefaultHasher::new();
data.hash(&mut s);
s.finish()
}

#[inline]
#[must_use]
pub const fn id(&self) -> u64 { self.id }
pub fn id(&self) -> u64 { self.content.id() }

#[inline]
#[must_use]
Expand All @@ -121,14 +105,12 @@ impl Entry {

#[inline]
#[must_use]
pub const fn is_utf8_string(&self) -> bool {
matches!(self.content, ClipboardContent::Plaintext(_))
}
pub const fn is_utf8_string(&self) -> bool { self.content.is_plaintext() }

#[inline]
#[must_use]
pub fn as_utf8_string(&self) -> String {
if let ClipboardContent::Plaintext(text) = &self.content {
if let ClipboardContent::Plaintext(ref text) = self.content {
text.clone()
} else {
String::new()
Expand All @@ -137,24 +119,18 @@ impl Entry {

#[must_use]
pub fn basic_information(&self) -> String {
let (content_type, size) = match &self.content {
ClipboardContent::Plaintext(text) => (mime::TEXT_PLAIN_UTF_8, text.len()),
ClipboardContent::Image { width: _, height: _, bytes } => {
(mime::IMAGE_PNG, bytes.len())
}
};

let timestamp = self
.timestamp
.to_offset(UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC))
.format(&Rfc3339)
.unwrap_or_default();
let size = humansize::format_size(size, humansize::BINARY);
let size = humansize::format_size(self.content.len(), humansize::BINARY);
let content_type = self.content.mime();
format!("[{content_type} {size} {timestamp}]")
}

#[must_use]
pub fn printable_data(&self, line_length: Option<usize>) -> String {
pub fn preview_information(&self, line_length: Option<usize>) -> String {
fn truncate(s: &str, max_chars: usize) -> &str {
match s.char_indices().nth(max_chars) {
None => s,
Expand Down Expand Up @@ -196,9 +172,6 @@ impl Entry {
self.timestamp = OffsetDateTime::now_utc();
}

#[must_use]
pub fn to_clipboard_content(&self) -> ClipboardContent { self.content.clone() }

#[inline]
#[must_use]
pub fn is_empty(&self) -> bool { self.content.is_empty() }
Expand Down Expand Up @@ -229,21 +202,16 @@ impl Entry {

#[inline]
#[must_use]
pub const fn mime(&self) -> mime::Mime {
match self.content {
ClipboardContent::Plaintext(_) => mime::TEXT_PLAIN_UTF_8,
ClipboardContent::Image { .. } => mime::IMAGE_PNG,
}
}
pub const fn mime(&self) -> mime::Mime { self.content.mime() }

#[inline]
pub fn metadata(&self, preview_length: Option<usize>) -> Metadata {
Metadata {
id: self.id,
id: self.id(),
kind: self.clipboard_kind,
timestamp: self.timestamp,
mime: self.mime(),
preview: self.printable_data(preview_length),
preview: self.preview_information(preview_length),
}
}

Expand All @@ -255,7 +223,6 @@ impl Default for Entry {
let content = ClipboardContent::Plaintext(String::new());
let sha256_digest = compute_sha256_digest(&content);
Self {
id: 0,
content,
clipboard_kind: ClipboardKind::Clipboard,
timestamp: OffsetDateTime::now_utc(),
Expand Down
Loading

0 comments on commit 7f77632

Please sign in to comment.