virtual_display_privacy_mode, switch privacy mode directly

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-11-14 19:36:51 +08:00
parent e2382a1465
commit 1905a81f9a
5 changed files with 26 additions and 17 deletions
flutter/lib
desktop/widgets
mobile/widgets
src

@ -1073,9 +1073,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
menuChildren: privacyModeList menuChildren: privacyModeList
.map((e) => Obx(() => CkbMenuButton( .map((e) => Obx(() => CkbMenuButton(
value: e.value, value: e.value,
onChanged: (privacyModeState.isEmpty || e.value) onChanged: e.onChanged,
? e.onChanged
: null,
child: e.child, child: e.child,
ffi: ffi))) ffi: ffi)))
.toList()), .toList()),

@ -277,9 +277,7 @@ void setPrivacyModeDialog(
visualDensity: VisualDensity.compact, visualDensity: VisualDensity.compact,
title: value.child, title: value.child,
value: value.value, value: value.value,
onChanged: (privacyModeState.isEmpty || value.value) onChanged: value.onChanged,
? value.onChanged
: null,
)) ))
.toList()), .toList()),
); );

@ -568,8 +568,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("True color (4:4:4)", "真彩模式4:4:4"), ("True color (4:4:4)", "真彩模式4:4:4"),
("Enable blocking user input", "允许阻止用户输入"), ("Enable blocking user input", "允许阻止用户输入"),
("id_input_tip", ""), ("id_input_tip", ""),
("privacy_mode_impl_mag_tip", "旧的 Windows API"), ("privacy_mode_impl_mag_tip", "模式 1 (不推荐)"),
("privacy_mode_impl_virtual_display_tip", "禁用物理显示器"), ("privacy_mode_impl_virtual_display_tip", "模式 2 (推荐)"),
("Enter privacy mode", "进入隐私模式"), ("Enter privacy mode", "进入隐私模式"),
("Exit privacy mode", "退出隐私模式"), ("Exit privacy mode", "退出隐私模式"),
].iter().cloned().collect(); ].iter().cloned().collect();

@ -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."), ("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."), ("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 (<domain>:<port>).\nIf you want to access a device on another server, please append the server address (<id>@<server_address>?key=<key_value>), for example,\n9123456234@192.168.16.1:21117?key=5Qbwsde3unUcJBtrx9ZkvUmwFNoExHzpryHuPUdqlWM=.\nIf you want to access a device on a public server, please input \"<id>@public\", the key is not needed for public server"), ("id_input_tip", "You can input an ID, a direct IP, or a domain with a port (<domain>:<port>).\nIf you want to access a device on another server, please append the server address (<id>@<server_address>?key=<key_value>), for example,\n9123456234@192.168.16.1:21117?key=5Qbwsde3unUcJBtrx9ZkvUmwFNoExHzpryHuPUdqlWM=.\nIf you want to access a device on a public server, please input \"<id>@public\", the key is not needed for public server"),
("privacy_mode_impl_mag_tip", "Old Windows magnifier API"), ("privacy_mode_impl_mag_tip", "Mode 1 (deprecated)"),
("privacy_mode_impl_virtual_display_tip", "Disable physical displays"), ("privacy_mode_impl_virtual_display_tip", "Mode 2 (recommended)"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

@ -177,23 +177,36 @@ fn get_supported_impl(impl_key: &str) -> String {
pub fn turn_on_privacy(impl_key: &str, conn_id: i32) -> Option<ResultType<bool>> { pub fn turn_on_privacy(impl_key: &str, conn_id: i32) -> Option<ResultType<bool>> {
// Check if privacy mode is already on or occupied by another one // Check if privacy mode is already on or occupied by another one
let mut privacy_mode_lock = PRIVACY_MODE.lock().unwrap(); 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 // Check or switch privacy mode implementation
let impl_key = get_supported_impl(impl_key); let impl_key = get_supported_impl(impl_key);
let mut cur_impl_lock = CUR_PRIVACY_MODE_IMPL.lock().unwrap(); 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 *cur_impl_lock != impl_key {
if let Some(creator) = PRIVACY_MODE_CREATOR if let Some(creator) = PRIVACY_MODE_CREATOR
.lock() .lock()
.unwrap() .unwrap()
.get(&(&impl_key as &str)) .get(&(&impl_key as &str))
{ {
if let Some(privacy_mode) = privacy_mode_lock.as_mut() {
privacy_mode.clear();
}
*privacy_mode_lock = Some(creator()); *privacy_mode_lock = Some(creator());
*cur_impl_lock = impl_key.to_owned(); *cur_impl_lock = impl_key.to_owned();
} else { } else {