patch: fix macos clipboard
1. wrong namings of NsPasteboard 2. wrap Pasteboard in Lazy Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
This commit is contained in:
parent
7880cba0f9
commit
36d4baaa8e
@ -24,10 +24,10 @@ libc = {version = "0.2"}
|
|||||||
dashmap = "5.5"
|
dashmap = "5.5"
|
||||||
percent-encoding = "2.3"
|
percent-encoding = "2.3"
|
||||||
utf16string = "0.2"
|
utf16string = "0.2"
|
||||||
|
once_cell = "1.18"
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
x11-clipboard = {git="https://github.com/clslaid/x11-clipboard", branch = "feat/store-batch"}
|
x11-clipboard = {git="https://github.com/clslaid/x11-clipboard", branch = "feat/store-batch"}
|
||||||
once_cell = "1.18"
|
|
||||||
x11rb = {version = "0.12", features = ["all-extensions"]}
|
x11rb = {version = "0.12", features = ["all-extensions"]}
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
|
@ -40,7 +40,6 @@ use utf16string::WStr;
|
|||||||
|
|
||||||
use crate::{send_data, ClipboardFile, CliprdrError};
|
use crate::{send_data, ClipboardFile, CliprdrError};
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
use super::LDAP_EPOCH_DELTA;
|
use super::LDAP_EPOCH_DELTA;
|
||||||
|
|
||||||
/// fuse server ready retry max times
|
/// fuse server ready retry max times
|
||||||
|
@ -89,7 +89,7 @@ fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, Cli
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, CliprdrError> {
|
fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, CliprdrError> {
|
||||||
use ns_clipboard::*;
|
use ns_clipboard::*;
|
||||||
let ns_pb = NSPasteboard::new(ignore_path)?;
|
let ns_pb = NsPasteboard::new(ignore_path)?;
|
||||||
Ok(Box::new(ns_pb) as Box<_>)
|
Ok(Box::new(ns_pb) as Box<_>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,15 +5,24 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use cacao::pasteboard::{Pasteboard, PasteboardName};
|
use cacao::pasteboard::{Pasteboard, PasteboardName};
|
||||||
|
use hbb_common::log;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use crate::{platform::unix::send_format_list, CliprdrError};
|
use crate::{platform::unix::send_format_list, CliprdrError};
|
||||||
|
|
||||||
use super::SysClipboard;
|
use super::SysClipboard;
|
||||||
|
|
||||||
|
static NS_PASTEBOARD: Lazy<Pasteboard> = Lazy::new(|| Pasteboard::named(PasteboardName::General));
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn wait_file_list() -> Option<Vec<PathBuf>> {
|
||||||
|
NS_PASTEBOARD
|
||||||
|
.get_file_urls()
|
||||||
|
.ok()
|
||||||
|
.map(|v| v.into_iter().map(|nsurl| nsurl.to_path_buf()).collect())
|
||||||
|
}
|
||||||
pub struct NsPasteboard {
|
pub struct NsPasteboard {
|
||||||
stopped: AtomicBool,
|
|
||||||
pasteboard: Pasteboard,
|
|
||||||
ignore_path: PathBuf,
|
ignore_path: PathBuf,
|
||||||
|
|
||||||
former_file_list: Mutex<Vec<PathBuf>>,
|
former_file_list: Mutex<Vec<PathBuf>>,
|
||||||
@ -21,22 +30,13 @@ pub struct NsPasteboard {
|
|||||||
|
|
||||||
impl NsPasteboard {
|
impl NsPasteboard {
|
||||||
pub fn new(ignore_path: &PathBuf) -> Result<Self, CliprdrError> {
|
pub fn new(ignore_path: &PathBuf) -> Result<Self, CliprdrError> {
|
||||||
let pasteboard = Pasteboard::named(PasteboardName::General);
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
stopped: AtomicBool::new(false),
|
stopped: AtomicBool::new(false),
|
||||||
ignore_path: ignore_path.to_owned(),
|
ignore_path: ignore_path.to_owned(),
|
||||||
pasteboard,
|
|
||||||
former_file_list: Mutex::new(vec![]),
|
former_file_list: Mutex::new(vec![]),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_file_list(&self) -> Option<Vec<PathBuf>> {
|
|
||||||
self.pasteboard
|
|
||||||
.get_file_urls()
|
|
||||||
.ok()
|
|
||||||
.map(|v| v.into_iter().map(|nsurl| nsurl.to_path_buf()).collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_stopped(&self) -> bool {
|
fn is_stopped(&self) -> bool {
|
||||||
self.stopped.load(Ordering::Relaxed)
|
self.stopped.load(Ordering::Relaxed)
|
||||||
@ -46,11 +46,8 @@ impl NsPasteboard {
|
|||||||
impl SysClipboard for NsPasteboard {
|
impl SysClipboard for NsPasteboard {
|
||||||
fn set_file_list(&self, paths: &[PathBuf]) -> Result<(), CliprdrError> {
|
fn set_file_list(&self, paths: &[PathBuf]) -> Result<(), CliprdrError> {
|
||||||
*self.former_file_list.lock() = paths.to_vec();
|
*self.former_file_list.lock() = paths.to_vec();
|
||||||
let uri_list: Vec<String> = paths.iter().map(encode_path_to_uri).collect();
|
NS_PASTEBOARD
|
||||||
let uri_list = uri_list.join("\n");
|
.set_file_urls(paths)
|
||||||
let uri_list = uri_list.as_bytes().to_vec();
|
|
||||||
self.pasteboard
|
|
||||||
.set_file_urls(uri_list)
|
|
||||||
.map_err(|_| CliprdrError::ClipboardInternalError)
|
.map_err(|_| CliprdrError::ClipboardInternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +59,7 @@ impl SysClipboard for NsPasteboard {
|
|||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let file_list = match self.wait_file_list() {
|
let file_list = match wait_file_list() {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => {
|
None => {
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user