patch: try fix flutter file copy
Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
This commit is contained in:
parent
2c9bae8111
commit
053723647b
@ -26,22 +26,19 @@ impl ContextSend {
|
||||
pub fn enable(enabled: bool) {
|
||||
let mut lock = CONTEXT_SEND.addr.lock().unwrap();
|
||||
if enabled {
|
||||
if lock.is_none() {
|
||||
match crate::create_cliprdr_context(
|
||||
true,
|
||||
false,
|
||||
CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS,
|
||||
) {
|
||||
Ok(context) => {
|
||||
log::info!("clipboard context for file transfer created.");
|
||||
*lock = Some(context)
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
"create clipboard context for file transfer: {}",
|
||||
err.to_string()
|
||||
);
|
||||
}
|
||||
if lock.is_some() {
|
||||
return;
|
||||
}
|
||||
match crate::create_cliprdr_context(true, false, CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS) {
|
||||
Ok(context) => {
|
||||
log::info!("clipboard context for file transfer created.");
|
||||
*lock = Some(context)
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
"create clipboard context for file transfer: {}",
|
||||
err.to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if let Some(_clp) = lock.take() {
|
||||
|
@ -25,33 +25,30 @@ pub fn create_cliprdr_context(
|
||||
_enable_others: bool,
|
||||
response_wait_timeout_secs: u32,
|
||||
) -> crate::ResultType<Box<dyn crate::CliprdrServiceContext>> {
|
||||
use hbb_common::log;
|
||||
use std::{fs::Permissions, os::unix::prelude::PermissionsExt};
|
||||
|
||||
use hbb_common::{config::APP_NAME, log};
|
||||
|
||||
if !enable_files {
|
||||
return Ok(Box::new(DummyCliprdrContext {}) as Box<_>);
|
||||
}
|
||||
|
||||
let timeout = std::time::Duration::from_secs(response_wait_timeout_secs as u64);
|
||||
let mut tmp_path = std::env::temp_dir();
|
||||
tmp_path.push("rustdesk-cliprdr");
|
||||
|
||||
let app_name = APP_NAME.read().unwrap().clone();
|
||||
|
||||
let mnt_path = format!("/tmp/{}/{}", app_name, "cliprdr");
|
||||
|
||||
// this function must be called after the main IPC is up
|
||||
std::fs::create_dir(&mnt_path).ok();
|
||||
std::fs::set_permissions(&mnt_path, Permissions::from_mode(0o777)).ok();
|
||||
|
||||
log::info!("clear previously mounted cliprdr FUSE");
|
||||
if let Err(e) = std::process::Command::new("umount").arg(&tmp_path).status() {
|
||||
log::warn!("umount {:?} may fail: {:?}", tmp_path, e);
|
||||
if let Err(e) = std::process::Command::new("umount").arg(&mnt_path).status() {
|
||||
log::warn!("umount {:?} may fail: {:?}", mnt_path, e);
|
||||
}
|
||||
|
||||
let rd_mnt = if !tmp_path.exists() {
|
||||
log::info!("create mount point: {}", tmp_path.display());
|
||||
std::fs::create_dir_all(tmp_path.clone())?;
|
||||
tmp_path
|
||||
} else if !tmp_path.is_dir() {
|
||||
log::error!("{} is occupied and is not a directory", tmp_path.display());
|
||||
return Err(CliprdrError::CliprdrInit.into());
|
||||
} else {
|
||||
tmp_path
|
||||
};
|
||||
|
||||
let linux_ctx = linux::ClipboardContext::new(timeout, rd_mnt)?;
|
||||
let linux_ctx = linux::ClipboardContext::new(timeout, mnt_path.parse().unwrap())?;
|
||||
log::debug!("start cliprdr FUSE");
|
||||
linux_ctx.run().expect("failed to start cliprdr FUSE");
|
||||
|
||||
|
@ -1073,7 +1073,6 @@ impl<T: InvokeUiSession> Remote<T> {
|
||||
}
|
||||
Some(login_response::Union::PeerInfo(pi)) => {
|
||||
self.handler.handle_peer_info(pi);
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
self.check_clipboard_file_context();
|
||||
if !(self.handler.is_file_transfer() || self.handler.is_port_forward()) {
|
||||
#[cfg(feature = "flutter")]
|
||||
@ -1703,7 +1702,6 @@ impl<T: InvokeUiSession> Remote<T> {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
fn check_clipboard_file_context(&self) {
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
{
|
||||
@ -1716,7 +1714,7 @@ impl<T: InvokeUiSession> Remote<T> {
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
fn handle_cliprdr_msg(&self, clip: hbb_common::message_proto::Cliprdr) {
|
||||
log::debug!("handling cliprdr msg from server peer");
|
||||
#[cfg(all(feature = "flutter", not(target_os = "linux")))]
|
||||
#[cfg(feature = "flutter")]
|
||||
if let Some(hbb_common::message_proto::cliprdr::Union::FormatList(_)) = &clip.union {
|
||||
if self.client_conn_id
|
||||
!= clipboard::get_client_conn_id(&crate::flutter::get_cur_peer_id()).unwrap_or(0)
|
||||
|
@ -1791,6 +1791,7 @@ impl Connection {
|
||||
{
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
if let Some(clip) = msg_2_clip(_clip) {
|
||||
log::debug!("got clipfile from client peer");
|
||||
self.send_to_cm(ipc::Data::ClipboardFile(clip))
|
||||
}
|
||||
}
|
||||
|
@ -575,6 +575,11 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
|
||||
}
|
||||
});
|
||||
|
||||
log::debug!(
|
||||
"start_ipc enable context_send: {}",
|
||||
Config::get_option("enable-file-transfer").is_empty()
|
||||
);
|
||||
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
ContextSend::enable(Config::get_option("enable-file-transfer").is_empty());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user