Replace copypasta with arboard (#1475)

* Replace copypasta with arboard

Closes https://github.com/emilk/egui/issues/1474

* Clean up deny.toml
This commit is contained in:
Emil Ernerfeldt 2022-04-10 16:41:07 +02:00 committed by GitHub
parent b036257729
commit 65d16695ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 107 deletions

123
Cargo.lock generated
View file

@ -90,6 +90,24 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "arboard"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6045ca509e4abacde2b884ac4618a51d0c017b5d85a3ee84a7226eb33b3154a9"
dependencies = [
"clipboard-win",
"log",
"objc",
"objc-foundation",
"objc_id",
"once_cell",
"parking_lot 0.12.0",
"thiserror",
"winapi",
"x11rb",
]
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.6" version = "0.3.6"
@ -516,11 +534,12 @@ dependencies = [
[[package]] [[package]]
name = "clipboard-win" name = "clipboard-win"
version = "3.1.1" version = "4.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342" checksum = "2f3e1238132dc01f081e1cbb9dace14e5ef4c3a51ee244bd982275fb514605db"
dependencies = [ dependencies = [
"lazy-bytes-cast", "error-code",
"str-buf",
"winapi", "winapi",
] ]
@ -590,20 +609,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "copypasta"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4423d79fed83ebd9ab81ec21fa97144300a961782158287dc9bf7eddac37ff0b"
dependencies = [
"clipboard-win",
"objc",
"objc-foundation",
"objc_id",
"smithay-clipboard",
"x11-clipboard",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.7.0" version = "0.7.0"
@ -1033,7 +1038,7 @@ dependencies = [
name = "egui-winit" name = "egui-winit"
version = "0.17.0" version = "0.17.0"
dependencies = [ dependencies = [
"copypasta", "arboard",
"dark-light", "dark-light",
"egui", "egui",
"epi", "epi",
@ -1247,6 +1252,16 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "error-code"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21"
dependencies = [
"libc",
"str-buf",
]
[[package]] [[package]]
name = "event-listener" name = "event-listener"
version = "2.5.2" version = "2.5.2"
@ -1425,6 +1440,16 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "gethostname"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.5" version = "0.2.5"
@ -1810,12 +1835,6 @@ dependencies = [
"arrayvec 0.7.2", "arrayvec 0.7.2",
] ]
[[package]]
name = "lazy-bytes-cast"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10257499f089cd156ad82d0a9cd57d9501fa2c989068992a97eb3c27836f206b"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -2509,15 +2528,6 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "quick-xml"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.15" version = "1.0.15"
@ -2989,16 +2999,6 @@ dependencies = [
"wayland-protocols", "wayland-protocols",
] ]
[[package]]
name = "smithay-clipboard"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "610b551bd25378bfd2b8e7a0fcbd83d427e8f2f6a40c47ae0f70688e9949dd55"
dependencies = [
"smithay-client-toolkit",
"wayland-client",
]
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.4.4" version = "0.4.4"
@ -3040,6 +3040,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "str-buf"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.8.0" version = "0.8.0"
@ -3790,6 +3796,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "winapi-wsapoll"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
@ -3894,15 +3909,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "x11-clipboard"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473068b7b80ac86a18328824f1054e5e007898c47b5bbc281bd7abe32bc3653c"
dependencies = [
"xcb",
]
[[package]] [[package]]
name = "x11-dl" name = "x11-dl"
version = "2.19.1" version = "2.19.1"
@ -3915,14 +3921,15 @@ dependencies = [
] ]
[[package]] [[package]]
name = "xcb" name = "x11rb"
version = "0.10.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c" checksum = "6e99be55648b3ae2a52342f9a870c0e138709a3493261ce9b469afe6e4df6d8a"
dependencies = [ dependencies = [
"libc", "gethostname",
"log", "nix 0.22.3",
"quick-xml", "winapi",
"winapi-wsapoll",
] ]
[[package]] [[package]]

View file

@ -16,28 +16,27 @@ yanked = "deny"
ignore = [ ignore = [
"RUSTSEC-2020-0071", # https://rustsec.org/advisories/RUSTSEC-2020-0071 - chrono/time: Potential segfault in the time crate "RUSTSEC-2020-0071", # https://rustsec.org/advisories/RUSTSEC-2020-0071 - chrono/time: Potential segfault in the time crate
"RUSTSEC-2020-0159", # https://rustsec.org/advisories/RUSTSEC-2020-0159 - chrono/time: Potential segfault in localtime_r invocations "RUSTSEC-2020-0159", # https://rustsec.org/advisories/RUSTSEC-2020-0159 - chrono/time: Potential segfault in localtime_r invocations
"RUSTSEC-2021-0019", # https://rustsec.org/advisories/RUSTSEC-2021-0019 - xcb - is being worked on: https://github.com/rust-x-bindings/rust-xcb/issues/107 "RUSTSEC-2021-0127", # https://rustsec.org/advisories/RUSTSEC-2021-0127 - https://github.com/bheisler/criterion.rs/issues/534
] ]
[bans] [bans]
multiple-versions = "deny" multiple-versions = "deny"
wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed
deny = [ deny = [
{ name = "openssl" }, # prefer rustls { name = "openssl" }, # prefer rustls
{ name = "openssl-sys" }, # prefer rustls { name = "openssl-sys" }, # prefer rustls
] ]
skip = [ skip = [
{ name = "ahash" }, # old version via dark-light { name = "ahash" }, # old version via dark-light
{ name = "arrayvec" }, # old version via tiny-skia { name = "arrayvec" }, # old version via tiny-skiaz
{ name = "hashbrown" }, # old version via dark-light { name = "hashbrown" }, # old version via dark-light
{ name = "time" }, # old version pulled in by unmaintianed crate 'chrono' { name = "time" }, # old version pulled in by unmaintianed crate 'chrono'
{ name = "ttf-parser" }, # different versions pulled in by ab_glyph and usvg { name = "ttf-parser" }, # different versions pulled in by ab_glyph and usvg
] ]
skip-tree = [ skip-tree = [
{ name = "criterion" }, # dev-dependnecy { name = "criterion" }, # dev-dependnecy
{ name = "glium" }, # legacy crate, lots of old dependencies { name = "glium" }, # legacy crate, lots of old dependencies
{ name = "glutin" }, # legacy crate, lots of old dependencies
] ]
@ -47,29 +46,25 @@ allow-osi-fsf-free = "neither"
confidence-threshold = 0.92 # We want really high confidence when inferring licenses from text confidence-threshold = 0.92 # We want really high confidence when inferring licenses from text
copyleft = "deny" copyleft = "deny"
allow = [ allow = [
"Apache-2.0 WITH LLVM-exception", # https://spdx.org/licenses/LLVM-exception.html # "Apache-2.0 WITH LLVM-exception", # https://spdx.org/licenses/LLVM-exception.html
"Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0) "Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)
"BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd) "BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd)
"BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised) "BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised)
"BSL-1.0", # https://tldrlegal.com/license/boost-software-license-1.0-explained "BSL-1.0", # https://tldrlegal.com/license/boost-software-license-1.0-explained
"CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/ "CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/
"ISC", # https://tldrlegal.com/license/-isc-license "ISC", # https://tldrlegal.com/license/-isc-license
"MIT", # https://tldrlegal.com/license/mit-license "MIT", # https://tldrlegal.com/license/mit-license
"MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/FAQ/ - see Q11 "MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/FAQ/ - see Q11
"OpenSSL", # https://www.openssl.org/source/license.html "OpenSSL", # https://www.openssl.org/source/license.html
"Zlib", # https://tldrlegal.com/license/zlib-libpng-license-(zlib) "Zlib", # https://tldrlegal.com/license/zlib-libpng-license-(zlib)
] ]
[[licenses.clarify]] [[licenses.clarify]]
name = "webpki" name = "webpki"
expression = "ISC" expression = "ISC"
license-files = [ license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
{ path = "LICENSE", hash = 0x001c7e6c }
]
[[licenses.clarify]] [[licenses.clarify]]
name = "ring" name = "ring"
expression = "MIT AND ISC AND OpenSSL" expression = "MIT AND ISC AND OpenSSL"
license-files = [ license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]
{ path = "LICENSE", hash = 0xbd0eed23 }
]

View file

@ -22,7 +22,7 @@ default = ["clipboard", "dark-light", "links"]
# enable cut/copy/paste to OS clipboard. # enable cut/copy/paste to OS clipboard.
# if disabled a clipboard will be simulated so you can still copy/paste within the egui app. # if disabled a clipboard will be simulated so you can still copy/paste within the egui app.
clipboard = ["copypasta"] clipboard = ["arboard"]
# implement bytemuck on most types. # implement bytemuck on most types.
bytemuck = ["egui/bytemuck"] bytemuck = ["egui/bytemuck"]
@ -51,8 +51,8 @@ winit = "0.26.1"
# Optional: # Optional:
epi = { version = "0.17.0", path = "../epi", optional = true } epi = { version = "0.17.0", path = "../epi", optional = true }
copypasta = { version = "0.7", optional = true } arboard = { version = "2.1", optional = true, default-features = false }
dark-light = { version = "0.2.1", optional = true } # detect dark mode system preference dark-light = { version = "0.2.1", optional = true } # detect dark mode system preference
glow = { version = "0.11", optional = true } glow = { version = "0.11", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] } serde = { version = "1.0", optional = true, features = ["derive"] }
webbrowser = { version = "0.6", optional = true } webbrowser = { version = "0.6", optional = true }

View file

@ -1,21 +1,21 @@
/// Handles interfacing either with the OS clipboard. /// Handles interfacing either with the OS clipboard.
/// If the "clipboard" feature is off it will instead simulate the clipboard locally. /// If the "clipboard" feature is off it will instead simulate the clipboard locally.
pub struct Clipboard { pub struct Clipboard {
#[cfg(feature = "copypasta")] #[cfg(feature = "arboard")]
copypasta: Option<copypasta::ClipboardContext>, arboard: Option<arboard::Clipboard>,
/// Fallback manual clipboard. /// Fallback manual clipboard.
#[cfg(not(feature = "copypasta"))] #[cfg(not(feature = "arboard"))]
clipboard: String, clipboard: String,
} }
impl Default for Clipboard { impl Default for Clipboard {
fn default() -> Self { fn default() -> Self {
Self { Self {
#[cfg(feature = "copypasta")] #[cfg(feature = "arboard")]
copypasta: init_copypasta(), arboard: init_arboard(),
#[cfg(not(feature = "copypasta"))] #[cfg(not(feature = "arboard"))]
clipboard: String::default(), clipboard: String::default(),
} }
} }
@ -23,11 +23,10 @@ impl Default for Clipboard {
impl Clipboard { impl Clipboard {
pub fn get(&mut self) -> Option<String> { pub fn get(&mut self) -> Option<String> {
#[cfg(feature = "copypasta")] #[cfg(feature = "arboard")]
if let Some(clipboard) = &mut self.copypasta { if let Some(clipboard) = &mut self.arboard {
use copypasta::ClipboardProvider as _; match clipboard.get_text() {
match clipboard.get_contents() { Ok(text) => Some(text),
Ok(contents) => Some(contents),
Err(err) => { Err(err) => {
tracing::error!("Paste error: {}", err); tracing::error!("Paste error: {}", err);
None None
@ -37,29 +36,28 @@ impl Clipboard {
None None
} }
#[cfg(not(feature = "copypasta"))] #[cfg(not(feature = "arboard"))]
Some(self.clipboard.clone()) Some(self.clipboard.clone())
} }
pub fn set(&mut self, text: String) { pub fn set(&mut self, text: String) {
#[cfg(feature = "copypasta")] #[cfg(feature = "arboard")]
if let Some(clipboard) = &mut self.copypasta { if let Some(clipboard) = &mut self.arboard {
use copypasta::ClipboardProvider as _; if let Err(err) = clipboard.set_text(text) {
if let Err(err) = clipboard.set_contents(text) {
tracing::error!("Copy/Cut error: {}", err); tracing::error!("Copy/Cut error: {}", err);
} }
} }
#[cfg(not(feature = "copypasta"))] #[cfg(not(feature = "arboard"))]
{ {
self.clipboard = text; self.clipboard = text;
} }
} }
} }
#[cfg(feature = "copypasta")] #[cfg(feature = "arboard")]
fn init_copypasta() -> Option<copypasta::ClipboardContext> { fn init_arboard() -> Option<arboard::Clipboard> {
match copypasta::ClipboardContext::new() { match arboard::Clipboard::new() {
Ok(clipboard) => Some(clipboard), Ok(clipboard) => Some(clipboard),
Err(err) => { Err(err) => {
tracing::error!("Failed to initialize clipboard: {}", err); tracing::error!("Failed to initialize clipboard: {}", err);