diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index 24cc60eb4..bdfa8f1e2 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -122,6 +122,28 @@ impl Remote { } pub async fn io_loop(&mut self, key: &str, token: &str, round: u32) { + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] + let _file_clip_context_holder = { + // `is_port_forward()` will not reach here, but we still check it for clarity. + if !self.handler.is_file_transfer() && !self.handler.is_port_forward() { + // It is ok to call this function multiple times. + ContextSend::enable(true); + Some(crate::SimpleCallOnReturn { + b: true, + f: Box::new(|| { + // No need to call `enable(false)` for sciter version, because each client of sciter version is a new process. + // It's better to check if the peers are windows(support file copy&paste), but it's not necessary. + #[cfg(feature = "flutter")] + if !crate::flutter::sessions::has_sessions_running(ConnType::DEFAULT_CONN) { + ContextSend::enable(false); + }; + }), + }) + } else { + None + } + }; + let mut last_recv_time = Instant::now(); let mut received = false; let conn_type = if self.handler.is_file_transfer() { @@ -310,12 +332,6 @@ impl Remote { Ok(()) }); } - - // It's better to check if the peers are windows, but it's not necessary. - #[cfg(feature = "flutter")] - if !crate::flutter::sessions::has_sessions_running(ConnType::DEFAULT_CONN) { - ContextSend::enable(false); - } } #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index 14baa6946..f76bd4e94 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -1739,18 +1739,6 @@ impl Session { #[tokio::main(flavor = "current_thread")] pub async fn io_loop(handler: Session, round: u32) { - // It is ok to call this function multiple times. - #[cfg(any( - target_os = "windows", - all( - any(target_os = "linux", target_os = "macos"), - feature = "unix-file-copy-paste" - ) - ))] - if !handler.is_file_transfer() && !handler.is_port_forward() { - clipboard::ContextSend::enable(true); - } - #[cfg(any(target_os = "android", target_os = "ios"))] let (sender, receiver) = mpsc::unbounded_channel::(); #[cfg(not(any(target_os = "android", target_os = "ios")))]