mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
try fix clipboard, flutter version
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -11,14 +11,12 @@ use std::{
|
||||
},
|
||||
};
|
||||
|
||||
#[cfg(windows)]
|
||||
use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, set_conn_enabled, ContextSend};
|
||||
use serde_derive::Serialize;
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::ipc::Connection;
|
||||
#[cfg(not(any(target_os = "ios")))]
|
||||
use crate::ipc::{self, Data};
|
||||
#[cfg(windows)]
|
||||
use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, ContextSend};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use hbb_common::tokio::sync::mpsc::unbounded_channel;
|
||||
#[cfg(windows)]
|
||||
@@ -37,6 +35,7 @@ use hbb_common::{
|
||||
task::spawn_blocking,
|
||||
},
|
||||
};
|
||||
use serde_derive::Serialize;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct Client {
|
||||
@@ -131,8 +130,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
|
||||
restart: bool,
|
||||
recording: bool,
|
||||
from_switch: bool,
|
||||
#[cfg(not(any(target_os = "ios")))]
|
||||
tx: mpsc::UnboundedSender<Data>,
|
||||
#[cfg(not(any(target_os = "ios")))] tx: mpsc::UnboundedSender<Data>,
|
||||
) {
|
||||
let client = Client {
|
||||
id,
|
||||
@@ -303,42 +301,12 @@ pub fn switch_back(id: i32) {
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
#[cfg(windows)]
|
||||
async fn enable_cliprdr_file_context(&mut self, conn_id: i32, enabled: bool) {
|
||||
if conn_id == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let pre_enabled = ContextSend::is_enabled();
|
||||
ContextSend::enable(enabled);
|
||||
if !pre_enabled && ContextSend::is_enabled() {
|
||||
allow_err!(
|
||||
self.stream
|
||||
.send(&Data::ClipboardFile(clipboard::ClipboardFile::MonitorReady))
|
||||
.await
|
||||
);
|
||||
}
|
||||
set_conn_enabled(conn_id, enabled);
|
||||
if !enabled {
|
||||
ContextSend::proc(|context: &mut Box<CliprdrClientContext>| -> u32 {
|
||||
empty_clipboard(context, conn_id);
|
||||
0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async fn run(&mut self) {
|
||||
use hbb_common::config::LocalConfig;
|
||||
|
||||
// for tmp use, without real conn id
|
||||
let mut write_jobs: Vec<fs::TransferJob> = Vec::new();
|
||||
|
||||
#[cfg(windows)]
|
||||
if self.conn_id > 0 {
|
||||
self.enable_cliprdr_file_context(self.conn_id, self.file_transfer_enabled)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
let rx_clip1;
|
||||
let mut rx_clip;
|
||||
@@ -382,15 +350,11 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
break;
|
||||
}
|
||||
Data::Close => {
|
||||
#[cfg(windows)]
|
||||
self.enable_cliprdr_file_context(self.conn_id, false).await;
|
||||
log::info!("cm ipc connection closed from connection request");
|
||||
break;
|
||||
}
|
||||
Data::Disconnected => {
|
||||
self.close = false;
|
||||
#[cfg(windows)]
|
||||
self.enable_cliprdr_file_context(self.conn_id, false).await;
|
||||
log::info!("cm ipc connection disconnect");
|
||||
break;
|
||||
}
|
||||
@@ -414,21 +378,18 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
handle_fs(fs, &mut write_jobs, &self.tx).await;
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
Data::ClipboardFile(_clip) => {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let conn_id = self.conn_id;
|
||||
ContextSend::proc(|context: &mut Box<CliprdrClientContext>| -> u32 {
|
||||
clipboard::server_clip_file(context, conn_id, _clip)
|
||||
});
|
||||
if !_clip.is_stopping_allowed() || self.file_transfer_enabled {
|
||||
let conn_id = self.conn_id;
|
||||
ContextSend::proc(|context: &mut Box<CliprdrClientContext>| -> u32 {
|
||||
clipboard::server_clip_file(context, conn_id, _clip)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
Data::ClipboardFileEnabled(_enabled) => {
|
||||
#[cfg(windows)]
|
||||
self.enable_cliprdr_file_context(self.conn_id, _enabled).await;
|
||||
}
|
||||
Data::Theme(dark) => {
|
||||
self.cm.change_theme(dark);
|
||||
}
|
||||
@@ -457,6 +418,11 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
}
|
||||
}
|
||||
Some(data) = self.rx.recv() => {
|
||||
if let Data::SwitchPermission{name, enabled} = &data {
|
||||
if name == "file" {
|
||||
self.file_transfer_enabled = *enabled;
|
||||
}
|
||||
}
|
||||
if self.stream.send(&data).await.is_err() {
|
||||
break;
|
||||
}
|
||||
@@ -464,7 +430,9 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
clip_file = rx_clip.recv() => match clip_file {
|
||||
Some(_clip) => {
|
||||
#[cfg(windows)]
|
||||
allow_err!(self.tx.send(Data::ClipboardFile(_clip)));
|
||||
if !_clip.is_stopping_allowed() || self.file_transfer_enabled {
|
||||
allow_err!(self.tx.send(Data::ClipboardFile(_clip)));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
//
|
||||
@@ -517,6 +485,13 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
|
||||
allow_err!(crate::privacy_win_mag::start());
|
||||
});
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
ContextSend::enable(
|
||||
Config::get_option("enable-file-transfer").is_empty(),
|
||||
true,
|
||||
crate::is_server(),
|
||||
);
|
||||
|
||||
match ipc::new_listener("_cm").await {
|
||||
Ok(mut incoming) => {
|
||||
while let Some(result) = incoming.next().await {
|
||||
|
||||
Reference in New Issue
Block a user