fix clipboard init sync

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-04-10 18:33:16 +08:00
parent 59ec397626
commit e9d5897b4b
2 changed files with 11 additions and 14 deletions

View File

@ -690,6 +690,7 @@ impl Client {
} }
} }
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
fn get_current_text_clipboard_msg() -> Option<Message> { fn get_current_text_clipboard_msg() -> Option<Message> {
let txt = &*OLD_CLIPBOARD_TEXT.lock().unwrap(); let txt = &*OLD_CLIPBOARD_TEXT.lock().unwrap();

View File

@ -925,11 +925,6 @@ impl<T: InvokeUiSession> Remote<T> {
self.handler.handle_peer_info(pi); self.handler.handle_peer_info(pi);
self.check_clipboard_file_context(); self.check_clipboard_file_context();
if !(self.handler.is_file_transfer() || self.handler.is_port_forward()) { if !(self.handler.is_file_transfer() || self.handler.is_port_forward()) {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let sender = self.sender.clone();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let permission_config = self.handler.get_permission_config();
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
Client::try_start_clipboard(None); Client::try_start_clipboard(None);
@ -938,21 +933,22 @@ impl<T: InvokeUiSession> Remote<T> {
Client::try_start_clipboard(Some( Client::try_start_clipboard(Some(
crate::client::ClientClipboardContext { crate::client::ClientClipboardContext {
cfg: permission_config.clone(), cfg: permission_config.clone(),
tx: sender.clone(), tx: self.sender.clone(),
}, },
)); ));
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
tokio::spawn(async move { if let Some(msg_out) = Client::get_current_text_clipboard_msg() {
// due to clipboard service interval time let sender = self.sender.clone();
sleep(common::CLIPBOARD_INTERVAL as f32 / 1_000.).await; let permission_config = self.handler.get_permission_config();
if permission_config.is_text_clipboard_required() { tokio::spawn(async move {
if let Some(msg_out) = Client::get_current_text_clipboard_msg() // due to clipboard service interval time
{ sleep(common::CLIPBOARD_INTERVAL as f32 / 1_000.).await;
if permission_config.is_text_clipboard_required() {
sender.send(Data::Message(msg_out)).ok(); sender.send(Data::Message(msg_out)).ok();
} }
} });
}); }
} }
if self.handler.is_file_transfer() { if self.handler.is_file_transfer() {