patch: fix active enable of file copy paste
Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
This commit is contained in:
parent
803509d952
commit
43aa62e212
@ -47,6 +47,19 @@ impl ContextSend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// make sure the clipboard context is enabled.
|
||||||
|
pub fn make_sure_enabled() -> ResultType<()> {
|
||||||
|
let mut lock = CONTEXT_SEND.addr.lock().unwrap();
|
||||||
|
if lock.is_some() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let ctx = crate::create_cliprdr_context(true, false, CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS)?;
|
||||||
|
*lock = Some(ctx);
|
||||||
|
log::info!("clipboard context for file transfer recreated.");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn proc<F: FnOnce(&mut Box<dyn CliprdrServiceContext>) -> ResultType<()>>(
|
pub fn proc<F: FnOnce(&mut Box<dyn CliprdrServiceContext>) -> ResultType<()>>(
|
||||||
f: F,
|
f: F,
|
||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
|
@ -63,7 +63,6 @@ fn add_remote_format(local_name: &str, remote_id: i32) {
|
|||||||
|
|
||||||
trait SysClipboard: Send + Sync {
|
trait SysClipboard: Send + Sync {
|
||||||
fn start(&self);
|
fn start(&self);
|
||||||
fn stop(&self);
|
|
||||||
|
|
||||||
fn set_file_list(&self, paths: &[PathBuf]) -> Result<(), CliprdrError>;
|
fn set_file_list(&self, paths: &[PathBuf]) -> Result<(), CliprdrError>;
|
||||||
fn get_file_list(&self) -> Vec<PathBuf>;
|
fn get_file_list(&self) -> Vec<PathBuf>;
|
||||||
@ -524,7 +523,7 @@ impl CliprdrServiceContext for ClipboardContext {
|
|||||||
if let Some(fuse_handle) = self.fuse_handle.lock().take() {
|
if let Some(fuse_handle) = self.fuse_handle.lock().take() {
|
||||||
fuse_handle.join();
|
fuse_handle.join();
|
||||||
}
|
}
|
||||||
self.clipboard.stop();
|
// we don't stop the clipboard, keep listening in case of restart
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
use std::{
|
use std::{collections::BTreeSet, path::PathBuf};
|
||||||
collections::BTreeSet,
|
|
||||||
path::PathBuf,
|
|
||||||
sync::atomic::{AtomicBool, Ordering},
|
|
||||||
};
|
|
||||||
|
|
||||||
use hbb_common::log;
|
use hbb_common::log;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@ -21,7 +17,6 @@ fn get_clip() -> Result<&'static Clipboard, CliprdrError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct X11Clipboard {
|
pub struct X11Clipboard {
|
||||||
stop: AtomicBool,
|
|
||||||
ignore_path: PathBuf,
|
ignore_path: PathBuf,
|
||||||
text_uri_list: Atom,
|
text_uri_list: Atom,
|
||||||
gnome_copied_files: Atom,
|
gnome_copied_files: Atom,
|
||||||
@ -47,7 +42,6 @@ impl X11Clipboard {
|
|||||||
.map_err(|_| CliprdrError::CliprdrInit)?;
|
.map_err(|_| CliprdrError::CliprdrInit)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
ignore_path: ignore_path.to_owned(),
|
ignore_path: ignore_path.to_owned(),
|
||||||
stop: AtomicBool::new(false),
|
|
||||||
text_uri_list,
|
text_uri_list,
|
||||||
gnome_copied_files,
|
gnome_copied_files,
|
||||||
nautilus_clipboard,
|
nautilus_clipboard,
|
||||||
@ -85,22 +79,12 @@ impl X11Clipboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn wait_file_list(&self) -> Result<Option<Vec<PathBuf>>, CliprdrError> {
|
fn wait_file_list(&self) -> Result<Option<Vec<PathBuf>>, CliprdrError> {
|
||||||
if self.stop.load(Ordering::Relaxed) {
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
let v = self.load(self.text_uri_list)?;
|
let v = self.load(self.text_uri_list)?;
|
||||||
let p = parse_plain_uri_list(v)?;
|
let p = parse_plain_uri_list(v)?;
|
||||||
Ok(Some(p))
|
Ok(Some(p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl X11Clipboard {
|
|
||||||
#[inline]
|
|
||||||
fn is_stopped(&self) -> bool {
|
|
||||||
self.stop.load(Ordering::Relaxed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SysClipboard for X11Clipboard {
|
impl SysClipboard for X11Clipboard {
|
||||||
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();
|
||||||
@ -118,13 +102,11 @@ impl SysClipboard for X11Clipboard {
|
|||||||
.map_err(|_| CliprdrError::ClipboardInternalError)
|
.map_err(|_| CliprdrError::ClipboardInternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop(&self) {
|
|
||||||
self.stop.store(true, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start(&self) {
|
fn start(&self) {
|
||||||
self.stop.store(false, Ordering::Relaxed);
|
{
|
||||||
|
// clear cached file list
|
||||||
|
*self.former_file_list.lock() = vec![];
|
||||||
|
}
|
||||||
loop {
|
loop {
|
||||||
let sth = match self.wait_file_list() {
|
let sth = match self.wait_file_list() {
|
||||||
Ok(sth) => sth,
|
Ok(sth) => sth,
|
||||||
@ -135,11 +117,6 @@ impl SysClipboard for X11Clipboard {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.is_stopped() {
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(paths) = sth else {
|
let Some(paths) = sth else {
|
||||||
// just sleep
|
// just sleep
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
@ -317,6 +317,9 @@ impl<T: InvokeUiSession> Remote<T> {
|
|||||||
if stop {
|
if stop {
|
||||||
ContextSend::set_is_stopped();
|
ContextSend::set_is_stopped();
|
||||||
} else {
|
} else {
|
||||||
|
if let Err(e) = ContextSend::make_sure_enabled() {
|
||||||
|
log::error!("failed to restart clipboard context: {}", e);
|
||||||
|
};
|
||||||
log::debug!("Send system clipboard message to remote");
|
log::debug!("Send system clipboard message to remote");
|
||||||
let msg = crate::clipboard_file::clip_2_msg(clip);
|
let msg = crate::clipboard_file::clip_2_msg(clip);
|
||||||
allow_err!(peer.send(&msg).await);
|
allow_err!(peer.send(&msg).await);
|
||||||
@ -1742,6 +1745,9 @@ impl<T: InvokeUiSession> Remote<T> {
|
|||||||
"Process clipboard message from server peer, stop: {}, is_stopping_allowed: {}, file_transfer_enabled: {}",
|
"Process clipboard message from server peer, stop: {}, is_stopping_allowed: {}, file_transfer_enabled: {}",
|
||||||
stop, is_stopping_allowed, file_transfer_enabled);
|
stop, is_stopping_allowed, file_transfer_enabled);
|
||||||
if !stop {
|
if !stop {
|
||||||
|
if let Err(e) = ContextSend::make_sure_enabled() {
|
||||||
|
log::error!("failed to restart clipboard context: {}", e);
|
||||||
|
};
|
||||||
let _ = ContextSend::proc(|context| -> ResultType<()> {
|
let _ = ContextSend::proc(|context| -> ResultType<()> {
|
||||||
context
|
context
|
||||||
.server_clip_file(self.client_conn_id, clip)
|
.server_clip_file(self.client_conn_id, clip)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user