Replace clipboard with arboard, which is actively maintained (#705)

This commit is contained in:
Tastaturtaste 2024-01-15 00:59:59 +01:00 committed by GitHub
parent ef7b96c157
commit dc27ed8ff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 603 additions and 226 deletions

815
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,11 +13,11 @@ version = "0.28.0"
doctest = true doctest = true
[dependencies] [dependencies]
arboard = { version = "3.3.0", optional = true, default-features = false, features = ["wayland-data-control"] }
chrono = { version = "0.4.19", default-features = false, features = [ chrono = { version = "0.4.19", default-features = false, features = [
"clock", "clock",
"serde", "serde",
] } ] }
clipboard = { version = "0.5.0", optional = true }
crossbeam = { version = "0.8.2", optional = true } crossbeam = { version = "0.8.2", optional = true }
crossterm = { version = "0.27.0", features = ["serde"] } crossterm = { version = "0.27.0", features = ["serde"] }
fd-lock = "3.0.3" fd-lock = "3.0.3"
@ -44,7 +44,7 @@ bashisms = []
external_printer = ["crossbeam"] external_printer = ["crossbeam"]
sqlite = ["rusqlite/bundled", "serde_json"] sqlite = ["rusqlite/bundled", "serde_json"]
sqlite-dynlib = ["rusqlite", "serde_json"] sqlite-dynlib = ["rusqlite", "serde_json"]
system_clipboard = ["clipboard"] system_clipboard = ["arboard"]
[[example]] [[example]]
name = "cwd_aware_hinter" name = "cwd_aware_hinter"

View File

@ -76,20 +76,20 @@ pub fn get_default_clipboard() -> LocalClipboard {
#[cfg(feature = "system_clipboard")] #[cfg(feature = "system_clipboard")]
mod system_clipboard { mod system_clipboard {
use super::*; use super::*;
use clipboard::{ClipboardContext, ClipboardProvider}; use arboard::Clipboard as Arboard;
/// Wrapper around [`clipboard`](https://docs.rs/clipboard) crate /// Wrapper around [`clipboard`](https://docs.rs/clipboard) crate
/// ///
/// Requires that the feature `system_clipboard` is enabled /// Requires that the feature `system_clipboard` is enabled
pub struct SystemClipboard { pub struct SystemClipboard {
cb: ClipboardContext, cb: Arboard,
local_copy: String, local_copy: String,
mode: ClipboardMode, mode: ClipboardMode,
} }
impl SystemClipboard { impl SystemClipboard {
pub fn new() -> Self { pub fn new() -> Self {
let cb = ClipboardProvider::new().unwrap(); let cb = Arboard::new().unwrap();
SystemClipboard { SystemClipboard {
cb, cb,
local_copy: String::new(), local_copy: String::new(),
@ -101,12 +101,12 @@ mod system_clipboard {
impl Clipboard for SystemClipboard { impl Clipboard for SystemClipboard {
fn set(&mut self, content: &str, mode: ClipboardMode) { fn set(&mut self, content: &str, mode: ClipboardMode) {
self.local_copy = content.to_owned(); self.local_copy = content.to_owned();
let _ = self.cb.set_contents(content.to_owned()); let _ = self.cb.set_text(content);
self.mode = mode; self.mode = mode;
} }
fn get(&mut self) -> (String, ClipboardMode) { fn get(&mut self) -> (String, ClipboardMode) {
let system_content = self.cb.get_contents().unwrap_or_default(); let system_content = self.cb.get_text().unwrap_or_default();
if system_content == self.local_copy { if system_content == self.local_copy {
// We assume the content was yanked inside the line editor and the last yank determined the mode. // We assume the content was yanked inside the line editor and the last yank determined the mode.
(system_content, self.mode) (system_content, self.mode)