Skip to content

Commit

Permalink
switch macos clipboard crate
Browse files Browse the repository at this point in the history
This cleans up the `cargo audit` output on linux because the `clipboard`
crate (which hasn't been updated in 3 years) depends on xcb=0.8.2
which is flagged by cargo audit.

We don't use `clipboard` on any platform except macos

This commit switches to the `clipboard_macos` crate; that appears to
use a copy and paste of the macos specific code from the `clipboard`
crate, so this shouldn't have any change in functionality.

refs: #1952
  • Loading branch information
wez committed May 9, 2022
1 parent e9e590c commit 6484b3a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
49 changes: 14 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion window/Cargo.toml
Expand Up @@ -81,7 +81,7 @@ xcb-imdkit = { version="0.2", git="https://github.com/wez/xcb-imdkit-rs.git", re
[target.'cfg(target_os="macos")'.dependencies]
cocoa = "0.20"
objc = "0.2"
clipboard = "0.5"
clipboard_macos = "0.1"
core-foundation = "0.7"
core-graphics = "0.19"
cgl = "0.3"
11 changes: 5 additions & 6 deletions window/src/os/macos/window.rs
Expand Up @@ -13,6 +13,7 @@ use crate::{
};
use anyhow::{anyhow, bail, ensure};
use async_trait::async_trait;
use clipboard_macos::Clipboard as ClipboardContext;
use cocoa::appkit::{
self, CGFloat, NSApplication, NSApplicationActivateIgnoringOtherApps,
NSApplicationPresentationOptions, NSBackingStoreBuffered, NSEvent, NSEventModifierFlags,
Expand Down Expand Up @@ -654,18 +655,16 @@ impl WindowOps for Window {
}

fn get_clipboard(&self, _clipboard: Clipboard) -> Future<String> {
use clipboard::ClipboardProvider;
Future::result(
clipboard::ClipboardContext::new()
.and_then(|mut ctx| ctx.get_contents())
ClipboardContext::new()
.and_then(|ctx| ctx.read())
.map_err(|e| anyhow!("Failed to get clipboard:{}", e)),
)
}

fn set_clipboard(&self, _clipboard: Clipboard, text: String) {
use clipboard::ClipboardProvider;
clipboard::ClipboardContext::new()
.and_then(|mut ctx| ctx.set_contents(text))
ClipboardContext::new()
.and_then(|mut ctx| ctx.write(text))
.ok();
}

Expand Down

0 comments on commit 6484b3a

Please sign in to comment.