From 1905a81f9af82a98c8c97960ad0c48f4f3ea261f Mon Sep 17 00:00:00 2001 From: fufesou Date: Tue, 14 Nov 2023 19:36:51 +0800 Subject: [PATCH] virtual_display_privacy_mode, switch privacy mode directly Signed-off-by: fufesou --- .../lib/desktop/widgets/remote_toolbar.dart | 4 +-- flutter/lib/mobile/widgets/dialog.dart | 4 +-- src/lang/cn.rs | 4 +-- src/lang/en.rs | 4 +-- src/privacy_mode.rs | 27 ++++++++++++++----- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart index 55da0fd69..ed399651f 100644 --- a/flutter/lib/desktop/widgets/remote_toolbar.dart +++ b/flutter/lib/desktop/widgets/remote_toolbar.dart @@ -1073,9 +1073,7 @@ class _DisplayMenuState extends State<_DisplayMenu> { menuChildren: privacyModeList .map((e) => Obx(() => CkbMenuButton( value: e.value, - onChanged: (privacyModeState.isEmpty || e.value) - ? e.onChanged - : null, + onChanged: e.onChanged, child: e.child, ffi: ffi))) .toList()), diff --git a/flutter/lib/mobile/widgets/dialog.dart b/flutter/lib/mobile/widgets/dialog.dart index 649e6d226..6b480c46e 100644 --- a/flutter/lib/mobile/widgets/dialog.dart +++ b/flutter/lib/mobile/widgets/dialog.dart @@ -277,9 +277,7 @@ void setPrivacyModeDialog( visualDensity: VisualDensity.compact, title: value.child, value: value.value, - onChanged: (privacyModeState.isEmpty || value.value) - ? value.onChanged - : null, + onChanged: value.onChanged, )) .toList()), ); diff --git a/src/lang/cn.rs b/src/lang/cn.rs index 9985051cb..a838701d5 100644 --- a/src/lang/cn.rs +++ b/src/lang/cn.rs @@ -568,8 +568,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("True color (4:4:4)", "真彩模式(4:4:4)"), ("Enable blocking user input", "允许阻止用户输入"), ("id_input_tip", ""), - ("privacy_mode_impl_mag_tip", "旧的 Windows API"), - ("privacy_mode_impl_virtual_display_tip", "禁用物理显示器"), + ("privacy_mode_impl_mag_tip", "模式 1 (不推荐)"), + ("privacy_mode_impl_virtual_display_tip", "模式 2 (推荐)"), ("Enter privacy mode", "进入隐私模式"), ("Exit privacy mode", "退出隐私模式"), ].iter().cloned().collect(); diff --git a/src/lang/en.rs b/src/lang/en.rs index 3d9012411..3afb27bc6 100644 --- a/src/lang/en.rs +++ b/src/lang/en.rs @@ -203,7 +203,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("elevated_switch_display_msg", "Switch to the primary display because multiple displays are not supported in elevated mode."), ("selinux_tip", "SELinux is enabled on your device, which may prevent RustDesk from running properly as controlled side."), ("id_input_tip", "You can input an ID, a direct IP, or a domain with a port (:).\nIf you want to access a device on another server, please append the server address (@?key=), for example,\n9123456234@192.168.16.1:21117?key=5Qbwsde3unUcJBtrx9ZkvUmwFNoExHzpryHuPUdqlWM=.\nIf you want to access a device on a public server, please input \"@public\", the key is not needed for public server"), - ("privacy_mode_impl_mag_tip", "Old Windows magnifier API"), - ("privacy_mode_impl_virtual_display_tip", "Disable physical displays"), + ("privacy_mode_impl_mag_tip", "Mode 1 (deprecated)"), + ("privacy_mode_impl_virtual_display_tip", "Mode 2 (recommended)"), ].iter().cloned().collect(); } diff --git a/src/privacy_mode.rs b/src/privacy_mode.rs index afa72f50c..99d16e996 100644 --- a/src/privacy_mode.rs +++ b/src/privacy_mode.rs @@ -177,23 +177,36 @@ fn get_supported_impl(impl_key: &str) -> String { pub fn turn_on_privacy(impl_key: &str, conn_id: i32) -> Option> { // Check if privacy mode is already on or occupied by another one let mut privacy_mode_lock = PRIVACY_MODE.lock().unwrap(); - if let Some(privacy_mode) = privacy_mode_lock.as_ref() { - let check_on_conn_id = privacy_mode.check_on_conn_id(conn_id); - match check_on_conn_id.as_ref() { - Ok(true) | Err(_) => return Some(check_on_conn_id), - _ => {} - } - } // Check or switch privacy mode implementation let impl_key = get_supported_impl(impl_key); let mut cur_impl_lock = CUR_PRIVACY_MODE_IMPL.lock().unwrap(); + + if let Some(privacy_mode) = privacy_mode_lock.as_ref() { + let check_on_conn_id = privacy_mode.check_on_conn_id(conn_id); + match check_on_conn_id.as_ref() { + Ok(true) => { + if *cur_impl_lock == impl_key { + return Some(Ok(true)); + } else { + // Same peer, switch to new implementation. + } + } + Err(_) => return Some(check_on_conn_id), + _ => {} + } + } + if *cur_impl_lock != impl_key { if let Some(creator) = PRIVACY_MODE_CREATOR .lock() .unwrap() .get(&(&impl_key as &str)) { + if let Some(privacy_mode) = privacy_mode_lock.as_mut() { + privacy_mode.clear(); + } + *privacy_mode_lock = Some(creator()); *cur_impl_lock = impl_key.to_owned(); } else {