fix cliprdr for windows after refactory

This commit is contained in:
rustdesk 2022-02-15 15:35:19 +08:00
parent 933969d1fe
commit 835db29c3f
5 changed files with 60 additions and 20 deletions

View File

@ -873,6 +873,8 @@ impl LoginConfigHandler {
self.config.lock_after_session_end
} else if name == "privacy-mode" {
self.config.privacy_mode
} else if name == "enable-file-transfer" {
self.config.enable_file_transfer
} else if name == "disable-audio" {
self.config.disable_audio
} else if name == "disable-clipboard" {
@ -1152,6 +1154,7 @@ pub enum Data {
CancelJob(i32),
RemovePortForward(i32),
AddPortForward((i32, String, i32)),
ToggleClipboardFile,
NewRDP,
}

View File

@ -143,6 +143,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Allow using keyboard and mouse", "允许使用键盘鼠标"),
("Allow using clipboard", "允许使用剪贴板"),
("Allow hearing sound", "允许听到声音"),
("Allow file transfer", "允许文件传输"),
("File transfer", "文件传输"),
("Connected", "已经连接"),
("Direct and encrypted connection", "加密直连"),
("Relayed and encrypted connection", "加密中继连接"),

View File

@ -851,7 +851,7 @@ impl Connection {
}
#[cfg(windows)]
Some(message::Union::cliprdr(clip)) => {
clipboard_file_service::handle_serve_clipboard_file_msg(self.inner.id, clip)
clipboard_file_service::handle_serve_cliprdr_msg(self.inner.id, clip)
}
Some(message::Union::file_action(fa)) => {
if self.file_transfer.is_some() {
@ -1017,11 +1017,13 @@ impl Connection {
if let Ok(q) = o.enable_file_transfer.enum_value() {
if q != BoolOption::NotSet {
self.enable_file_transfer = q == BoolOption::Yes;
s.write().unwrap().subscribe(
super::clipboard_file_service::NAME,
self.inner.clone(),
self.file_transfer_enabled(),
);
if let Some(s) = self.server.upgrade() {
s.write().unwrap().subscribe(
super::clipboard_file_service::NAME,
self.inner.clone(),
self.file_transfer_enabled(),
);
}
}
}
if let Ok(q) = o.disable_clipboard.enum_value() {

View File

@ -406,7 +406,7 @@ function adjustHeader() {
view.on("size", adjustHeader);
handler.addConnection(0, false, 0, "", "test1", true, false, false, true, true);
// handler.addConnection(0, false, 0, "", "test1", true, false, false, true, true);
// handler.addConnection(1, false, 0, "", "test2--------", true, false, false, false, false);
// handler.addConnection(2, false, 0, "", "test3", true, false, false, false, false);
// handler.newMessage(0, 'h');

View File

@ -4,7 +4,7 @@ use crate::common::{
};
#[cfg(windows)]
use clipboard::{
cliprdrfile::CliprdrClientContext, create_cliprdr_context as create_clipboard_file_context,
cliprdr::CliprdrClientContext, create_cliprdr_context as create_clipboard_file_context,
get_rx_client_msg as get_clipboard_file_rx_client_msg, server_msg as clipboard_file_msg,
ConnID as ClipboardFileConnID,
};
@ -57,6 +57,7 @@ fn get_key_state(key: enigo::Key) -> bool {
static mut IS_IN: bool = false;
static mut KEYBOARD_HOOKED: bool = false;
static mut SERVER_KEYBOARD_ENABLED: bool = true;
static mut SERVER_FILE_TRANSFER_ENABLED: bool = true;
static mut SERVER_CLIPBOARD_ENABLED: bool = true;
#[derive(Default)]
@ -394,7 +395,10 @@ impl Handler {
}
fn toggle_option(&mut self, name: String) {
let msg = self.lc.write().unwrap().toggle_option(name);
let msg = self.lc.write().unwrap().toggle_option(name.clone());
if name == "enable-file-transfer" {
self.send(Data::ToggleClipboardFile);
}
if let Some(msg) = msg {
self.send(Data::Message(msg));
}
@ -1166,15 +1170,6 @@ async fn io_loop(handler: Handler) {
.map(|v| v.render_frame(data).ok());
});
#[cfg(windows)]
let clipboard_file_context = match create_clipboard_file_context(true, false) {
Ok(context) => Some(context),
Err(err) => {
handler.msgbox("error", "Create clipboard error", &err.to_string());
None
}
};
let mut remote = Remote {
handler,
video_sender,
@ -1189,10 +1184,11 @@ async fn io_loop(handler: Handler) {
last_update_jobs_status: (Instant::now(), Default::default()),
first_frame: false,
#[cfg(windows)]
clipboard_file_context,
clipboard_file_context: None,
#[cfg(windows)]
pid: std::process::id(),
};
remote.check_clipboard_file_context();
remote.io_loop().await;
}
@ -1251,6 +1247,7 @@ impl Remote {
unsafe {
SERVER_KEYBOARD_ENABLED = true;
SERVER_CLIPBOARD_ENABLED = true;
SERVER_FILE_TRANSFER_ENABLED = true;
}
self.handler
.call("setConnectionType", &make_args!(peer.is_secured(), direct));
@ -1334,6 +1331,7 @@ impl Remote {
unsafe {
SERVER_KEYBOARD_ENABLED = false;
SERVER_CLIPBOARD_ENABLED = false;
SERVER_FILE_TRANSFER_ENABLED = false;
}
}
@ -1414,6 +1412,9 @@ impl Remote {
.handle_login_from_ui(password, remember, peer)
.await;
}
Data::ToggleClipboardFile => {
self.check_clipboard_file_context();
}
Data::Message(msg) => {
allow_err!(peer.send(&msg).await);
}
@ -1679,7 +1680,7 @@ impl Remote {
Some(message::Union::cliprdr(clip)) => {
if !self.handler.lc.read().unwrap().disable_clipboard {
if let Some(context) = &mut self.clipboard_file_context {
let res = clipboard_file_msg(
clipboard_file_msg(
context,
ClipboardFileConnID {
server_conn_id: 0,
@ -1753,6 +1754,10 @@ impl Remote {
.call("setPermission", &make_args!("audio", p.enabled));
}
Permission::File => {
unsafe {
SERVER_FILE_TRANSFER_ENABLED = p.enabled;
}
self.check_clipboard_file_context();
self.handler
.call("setPermission", &make_args!("file", p.enabled));
}
@ -1796,6 +1801,34 @@ impl Remote {
}
true
}
fn check_clipboard_file_context(&mut self) {
#[cfg(windows)]
{
let enabled = unsafe { SERVER_FILE_TRANSFER_ENABLED }
&& self.handler.lc.read().unwrap().enable_file_transfer;
if enabled == self.clipboard_file_context.is_none() {
self.clipboard_file_context = if enabled {
match create_clipboard_file_context(true, false) {
Ok(context) => {
log::info!("clipboard context for file transfer created.");
Some(context)
}
Err(err) => {
log::error!(
"Create clipboard context for file transfer: {}",
err.to_string()
);
None
}
}
} else {
log::info!("clipboard context for file transfer destroyed.");
None
};
}
}
}
}
fn make_fd(id: i32, entries: &Vec<FileEntry>, only_count: bool) -> Value {