diff --git a/flutter/lib/desktop/pages/file_manager_tab_page.dart b/flutter/lib/desktop/pages/file_manager_tab_page.dart index 68ad2529c..5dd0629fb 100644 --- a/flutter/lib/desktop/pages/file_manager_tab_page.dart +++ b/flutter/lib/desktop/pages/file_manager_tab_page.dart @@ -43,7 +43,7 @@ class _FileManagerTabPageState extends State { void initState() { super.initState(); - tabController.onRemove = (_, id) => onRemoveId(id); + tabController.onRemoved = (_, id) => onRemoveId(id); rustDeskWinManager.setMethodHandler((call, fromWindowId) async { print( diff --git a/flutter/lib/desktop/pages/port_forward_tab_page.dart b/flutter/lib/desktop/pages/port_forward_tab_page.dart index 6d7390493..de3ba0d92 100644 --- a/flutter/lib/desktop/pages/port_forward_tab_page.dart +++ b/flutter/lib/desktop/pages/port_forward_tab_page.dart @@ -46,7 +46,7 @@ class _PortForwardTabPageState extends State { void initState() { super.initState(); - tabController.onRemove = (_, id) => onRemoveId(id); + tabController.onRemoved = (_, id) => onRemoveId(id); rustDeskWinManager.setMethodHandler((call, fromWindowId) async { debugPrint( diff --git a/flutter/lib/desktop/pages/remote_tab_page.dart b/flutter/lib/desktop/pages/remote_tab_page.dart index b73dacec2..b3ebb5497 100644 --- a/flutter/lib/desktop/pages/remote_tab_page.dart +++ b/flutter/lib/desktop/pages/remote_tab_page.dart @@ -59,11 +59,12 @@ class _ConnectionTabPageState extends State { void initState() { super.initState(); - tabController.onRemove = (_, id) => onRemoveId(id); + tabController.onRemoved = (_, id) => onRemoveId(id); + tabController.onSelected = (_, id) => onSelectId(id); rustDeskWinManager.setMethodHandler((call, fromWindowId) async { print( - "call ${call.method} with args ${call.arguments} from window ${fromWindowId}"); + "call ${call.method} with args ${call.arguments} from window $fromWindowId"); final RxBool fullscreen = Get.find(tag: 'fullscreen'); // for simplify, just replace connectionId @@ -174,6 +175,10 @@ class _ConnectionTabPageState extends State { _update_remote_count(); } + void onSelectId(String id) { + bind.setCurSessionId(id: id); + } + int windowId() { return widget.params["windowId"]; } diff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dart index 2211a0b0d..d04f7871f 100644 --- a/flutter/lib/desktop/pages/server_page.dart +++ b/flutter/lib/desktop/pages/server_page.dart @@ -30,7 +30,7 @@ class _DesktopServerPageState extends State void initState() { gFFI.ffiModel.updateEventListener(""); windowManager.addListener(this); - tabController.onRemove = (_, id) => onRemoveId(id); + tabController.onRemoved = (_, id) => onRemoveId(id); super.initState(); } @@ -99,7 +99,7 @@ class ConnectionManagerState extends State { @override void initState() { gFFI.serverModel.updateClientState(); - gFFI.serverModel.tabController.onSelected = (index) => + gFFI.serverModel.tabController.onSelected = (index, _) => gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id); super.initState(); } diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart index 92c868c34..7fae47e69 100644 --- a/flutter/lib/desktop/widgets/tabbar_widget.dart +++ b/flutter/lib/desktop/widgets/tabbar_widget.dart @@ -70,10 +70,11 @@ class DesktopTabController { final DesktopTabType tabType; /// index, key - Function(int, String)? onRemove; - Function(int)? onSelected; + Function(int, String)? onRemoved; + Function(int, String)? onSelected; - DesktopTabController({required this.tabType}); + DesktopTabController( + {required this.tabType, this.onRemoved, this.onSelected}); int get length => state.value.tabs.length; @@ -114,7 +115,7 @@ class DesktopTabController { state.value.tabs.removeAt(index); state.value.scrollController.itemCount = state.value.tabs.length; jumpTo(toIndex); - onRemove?.call(index, key); + onRemoved?.call(index, key); } void jumpTo(int index) { @@ -134,7 +135,8 @@ class DesktopTabController { })); }); if (state.value.tabs.length > index) { - onSelected?.call(index); + final key = state.value.tabs[index].key; + onSelected?.call(index, key); } } @@ -146,7 +148,7 @@ class DesktopTabController { void closeBy(String? key) { if (!isDesktop) return; - assert(onRemove != null); + assert(onRemoved != null); if (key == null) { if (state.value.selected < state.value.tabs.length) { remove(state.value.selected); diff --git a/libs/clipboard/src/lib.rs b/libs/clipboard/src/lib.rs index fa65adc37..b992e39e3 100644 --- a/libs/clipboard/src/lib.rs +++ b/libs/clipboard/src/lib.rs @@ -78,8 +78,16 @@ lazy_static::lazy_static! { static ref PROCESS_SIDE: RwLock = RwLock::new(ProcessSide::UnknownSide); } -#[inline] -pub fn get_rx_cliprdr_client<'a>( +pub fn get_client_conn_id(peer_id: &str) -> Option { + VEC_MSG_CHANNEL + .read() + .unwrap() + .iter() + .find(|x| x.peer_id == peer_id.to_owned()) + .map(|x| x.conn_id) +} + +pub fn get_rx_cliprdr_client( peer_id: &str, ) -> (i32, Arc>>) { let mut lock = VEC_MSG_CHANNEL.write().unwrap(); @@ -102,10 +110,7 @@ pub fn get_rx_cliprdr_client<'a>( } } -#[inline] -pub fn get_rx_cliprdr_server<'a>( - conn_id: i32, -) -> Arc>> { +pub fn get_rx_cliprdr_server(conn_id: i32) -> Arc>> { let mut lock = VEC_MSG_CHANNEL.write().unwrap(); match lock.iter().find(|x| x.conn_id == conn_id) { Some(msg_channel) => msg_channel.receiver.clone(), diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index 662addea5..b108c1ad0 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -1178,6 +1178,16 @@ impl Remote { #[cfg(windows)] fn handle_cliprdr_msg(&self, clip: message_proto::Cliprdr) { if !self.handler.lc.read().unwrap().disable_clipboard { + #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] + if let Some(message_proto::cliprdr::Union::FormatList(_)) = &clip.union { + if self.client_conn_id + != clipboard::get_client_conn_id(&crate::flutter::get_cur_session_id()) + .unwrap_or(0) + { + return; + } + } + if let Some(clip) = crate::clipboard_file::msg_2_clip(clip) { ContextSend::proc(|context: &mut Box| -> u32 { clipboard::server_clip_file(context, self.client_conn_id, clip) diff --git a/src/flutter.rs b/src/flutter.rs index d477b62d5..5e844f910 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -567,7 +567,7 @@ pub fn make_fd_flutter(id: i32, entries: &Vec, only_count: bool) -> S } pub fn get_cur_session_id() -> String { - *CUR_SESSION_ID.read().unwrap() + CUR_SESSION_ID.read().unwrap().clone() } pub fn set_cur_session_id(id: String) { diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 5fdb3122c..cddaf4d79 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -1052,6 +1052,10 @@ pub fn main_update_me() -> SyncReturn { SyncReturn(true) } +pub fn set_cur_session_id(id: String) { + super::flutter::set_cur_session_id(id) +} + pub fn install_show_run_without_install() -> SyncReturn { SyncReturn(show_run_without_install()) } diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 9c45ad269..70ea1a15c 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -259,7 +259,6 @@ impl IpcTaskRunner { use hbb_common::config::LocalConfig; // for tmp use, without real conn id - let conn_id_tmp = -1; let mut write_jobs: Vec = Vec::new(); let mut close = true; @@ -321,9 +320,8 @@ impl IpcTaskRunner { log::info!("cm ipc connection disconnect"); break; } - Data::PrivacyModeState(_) => { - self.conn_id = conn_id_tmp; - allow_err!(self.tx.send(data)); + Data::PrivacyModeState((id, _)) => { + cm_inner_send(id, data); } Data::ClickTime(ms) => { CLICK_TIME.store(ms, Ordering::SeqCst); @@ -338,7 +336,6 @@ impl IpcTaskRunner { #[cfg(windows)] { let conn_id = self.conn_id; - ContextSend::proc(|context: &mut Box| -> u32 { clipboard::server_clip_file(context, conn_id, _clip) }); @@ -380,12 +377,10 @@ impl IpcTaskRunner { }, } } - if self.conn_id != 0 && self.conn_id != conn_id_tmp { - self.cm.remove_connection(self.conn_id, close); - } } async fn ipc_task(stream: Connection, cm: ConnectionManager) { + log::debug!("ipc task begin"); let (tx, rx) = mpsc::unbounded_channel::(); let mut task_runner = Self { stream, @@ -401,6 +396,10 @@ impl IpcTaskRunner { if task_runner.conn_id > 0 { task_runner.run().await; } + if task_runner.conn_id > 0 { + task_runner.cm.remove_connection(task_runner.conn_id, close); + } + log::debug!("ipc task end"); } } @@ -731,3 +730,17 @@ fn send_raw(msg: Message, tx: &UnboundedSender) { err => allow_err!(err), } } + +#[cfg(windows)] +fn cm_inner_send(id: i32, data: Data) { + let lock = CLIENTS.read().unwrap(); + if id != 0 { + if let Some(s) = lock.get(&id) { + allow_err!(s.tx.send(data)); + } + } else { + for s in lock.values() { + allow_err!(s.tx.send(data.clone())); + } + } +}