From d6c9639c5da78d1197d412934b6f75c411f6ddd9 Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 31 Oct 2022 10:04:59 +0800 Subject: [PATCH 1/2] fix: win remote and file transfer , simultaneous connection Signed-off-by: fufesou --- src/client/io_loop.rs | 21 +++++++++++++++------ src/common.rs | 1 - src/server/input_service.rs | 6 +++--- src/server/video_service.rs | 8 ++++++-- src/ui.rs | 2 +- src/ui/remote.rs | 2 -- src/ui_cm_interface.rs | 6 +++--- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index b108c1ad0..e4e604cde 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -1,5 +1,5 @@ use crate::client::{ - Client, CodecFormat, FileManager, MediaData, MediaSender, QualityStatus, MILLI1, SEC30, + Client, CodecFormat, MediaData, MediaSender, QualityStatus, MILLI1, SEC30, SERVER_CLIPBOARD_ENABLED, SERVER_FILE_TRANSFER_ENABLED, SERVER_KEYBOARD_ENABLED, }; use crate::common; @@ -15,7 +15,7 @@ use crate::{client::Data, client::Interface}; use hbb_common::config::{PeerConfig, TransferSerde}; use hbb_common::fs::{ can_enable_overwrite_detection, get_job, get_string, new_send_confirm, DigestCheckResult, - RemoveJobMeta, TransferJobMeta, + RemoveJobMeta, }; use hbb_common::message_proto::permission_info::Permission; use hbb_common::protobuf::Message as _; @@ -23,6 +23,7 @@ use hbb_common::rendezvous_proto::ConnType; use hbb_common::tokio::{ self, sync::mpsc, + sync::Mutex as TokioMutex, time::{self, Duration, Instant, Interval}, }; use hbb_common::{ @@ -113,15 +114,23 @@ impl Remote { // just build for now #[cfg(not(windows))] let (_tx_holder, mut rx_clip_client) = mpsc::unbounded_channel::(); + #[cfg(windows)] - let (client_conn_id, rx_clip_client1) = - clipboard::get_rx_cliprdr_client(&self.handler.id); + let (_tx_holder, rx) = mpsc::unbounded_channel(); #[cfg(windows)] - let mut rx_clip_client = rx_clip_client1.lock().await; + let mut rx_clip_client_lock = Arc::new(TokioMutex::new(rx)); #[cfg(windows)] { - self.client_conn_id = client_conn_id; + let is_conn_not_default = self.handler.is_file_transfer() + || self.handler.is_port_forward() + || self.handler.is_rdp(); + if !is_conn_not_default { + (self.client_conn_id, rx_clip_client_lock) = + clipboard::get_rx_cliprdr_client(&self.handler.id); + }; } + #[cfg(windows)] + let mut rx_clip_client = rx_clip_client_lock.lock().await; let mut status_timer = time::interval(Duration::new(1, 0)); diff --git a/src/common.rs b/src/common.rs index 3022e5b56..8a9890319 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,5 +1,4 @@ use std::{ - collections::HashMap, future::Future, sync::{Arc, Mutex}, }; diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 2f2dd7743..546013673 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -725,7 +725,7 @@ fn legacy_keyboard_mode(evt: &KeyEvent) { // disable numlock if press home etc when numlock is on, // because we will get numpad value (7,8,9 etc) if not #[cfg(windows)] - let mut disable_numlock = false; + let mut _disable_numlock = false; #[cfg(target_os = "macos")] en.reset_flag(); // When long-pressed the command key, then press and release @@ -775,8 +775,8 @@ fn legacy_keyboard_mode(evt: &KeyEvent) { if let Some(key) = KEY_MAP.get(&ck.value()) { #[cfg(windows)] if let Some(_) = NUMPAD_KEY_MAP.get(&ck.value()) { - disable_numlock = en.get_key_state(Key::NumLock); - if disable_numlock { + _disable_numlock = en.get_key_state(Key::NumLock); + if _disable_numlock { en.key_down(Key::NumLock).ok(); en.key_up(Key::NumLock); } diff --git a/src/server/video_service.rs b/src/server/video_service.rs index b583a0ae3..5927bddec 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -468,6 +468,7 @@ fn run(sp: GenericService) -> ResultType<()> { #[cfg(windows)] start_uac_elevation_check(); + #[cfg(target_os = "linux")] let mut would_block_count = 0u32; while sp.ok() { @@ -570,9 +571,9 @@ fn run(sp: GenericService) -> ResultType<()> { try_gdi += 1; } - would_block_count += 1; #[cfg(target_os = "linux")] { + would_block_count += 1; if !scrap::is_x11() { if would_block_count >= 100 { // For now, the user should choose and agree screen sharing agiain. @@ -600,7 +601,10 @@ fn run(sp: GenericService) -> ResultType<()> { return Err(err.into()); } _ => { - would_block_count = 0; + #[cfg(target_os = "linux")] + { + would_block_count = 0; + } } } diff --git a/src/ui.rs b/src/ui.rs index c25aaf670..b11e574ba 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -15,7 +15,7 @@ use hbb_common::{ protobuf::Message as _, rendezvous_proto::*, tcp::FramedStream, - tokio::{self, sync::mpsc, time}, + tokio::{self, sync::mpsc}, }; use crate::common::get_app_name; diff --git a/src/ui/remote.rs b/src/ui/remote.rs index ce10827c4..62df85250 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -18,8 +18,6 @@ use hbb_common::{ allow_err, fs::TransferJobMeta, log, message_proto::*, rendezvous_proto::ConnType, }; -#[cfg(windows)] -use crate::clipboard_file::*; use crate::{ client::*, ui_interface::has_hwcodec, diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 7296f8738..5fb3c76fd 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -11,7 +11,7 @@ use std::{ }; #[cfg(windows)] -use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, ContextSend}; +use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, set_conn_enabled, ContextSend}; use serde_derive::Serialize; use crate::ipc::{self, new_listener, Connection, Data}; @@ -247,10 +247,10 @@ impl IpcTaskRunner { .await ); } - clipboard::set_conn_enabled(conn_id, enabled); + set_conn_enabled(conn_id, enabled); if !enabled { ContextSend::proc(|context: &mut Box| -> u32 { - clipboard::empty_clipboard(context, conn_id); + empty_clipboard(context, conn_id); 0 }); } From a362446effd54be5804aadf29d7ce1acae57e386 Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 31 Oct 2022 10:18:22 +0800 Subject: [PATCH 2/2] remove some compilation warnings Signed-off-by: fufesou --- src/flutter.rs | 1 + src/flutter_ffi.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/flutter.rs b/src/flutter.rs index 5e844f910..5b8504b4d 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -418,6 +418,7 @@ pub fn session_start_(id: &str, event_stream: StreamSink) -> ResultTy pub mod connection_manager { use std::collections::HashMap; + #[cfg(any(target_os = "android"))] use hbb_common::log; #[cfg(any(target_os = "android"))] use scrap::android::call_main_service_set_by_name; diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index cddaf4d79..45bcd12e3 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -7,13 +7,14 @@ use std::{ use flutter_rust_bridge::{StreamSink, SyncReturn, ZeroCopyBuffer}; use serde_json::json; +use hbb_common::ResultType; use hbb_common::{ config::{self, LocalConfig, PeerConfig, ONLINE}, fs, log, }; -use hbb_common::{message_proto::Hash, ResultType}; use crate::flutter::{self, SESSIONS}; +#[cfg(target_os = "android")] use crate::start_server; use crate::ui_interface::{self, *}; use crate::{ @@ -362,7 +363,7 @@ pub fn session_create_dir(id: String, act_id: i32, path: String, is_remote: bool } } -pub fn session_read_local_dir_sync(id: String, path: String, show_hidden: bool) -> String { +pub fn session_read_local_dir_sync(_id: String, path: String, show_hidden: bool) -> String { if let Ok(fd) = fs::read_dir(&fs::get_path(&path), show_hidden) { return make_fd_to_json(fd.id, path, &fd.entries); }