mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
refact: win, virtual display (#7767)
* refact: win, virtual display Signed-off-by: fufesou <shuanglongchen@yeah.net> * Update flutter-build.yml --------- Signed-off-by: fufesou <shuanglongchen@yeah.net> Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
@@ -72,6 +72,10 @@ pub struct PrivacyModeImpl {
|
||||
}
|
||||
|
||||
impl PrivacyMode for PrivacyModeImpl {
|
||||
fn is_async_privacy_mode(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn init(&self) -> ResultType<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use super::{PrivacyMode, PrivacyModeState, INVALID_PRIVACY_MODE_CONN_ID, NO_DISPLAYS};
|
||||
use super::{PrivacyMode, PrivacyModeState, INVALID_PRIVACY_MODE_CONN_ID, NO_PHYSICAL_DISPLAYS};
|
||||
use crate::virtual_display_manager;
|
||||
use hbb_common::{allow_err, bail, config::Config, log, ResultType};
|
||||
use std::{
|
||||
io::Error,
|
||||
ops::{Deref, DerefMut},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use virtual_display::MonitorMode;
|
||||
use winapi::{
|
||||
@@ -27,7 +29,6 @@ use winapi::{
|
||||
|
||||
pub(super) const PRIVACY_MODE_IMPL: &str = "privacy_mode_impl_virtual_display";
|
||||
|
||||
const IDD_DEVICE_STRING: &'static str = "RustDeskIddDriver Device\0";
|
||||
const CONFIG_KEY_REG_RECOVERY: &str = "reg_recovery";
|
||||
|
||||
struct Display {
|
||||
@@ -137,8 +138,9 @@ impl PrivacyModeImpl {
|
||||
primary,
|
||||
};
|
||||
|
||||
if let Ok(s) = std::string::String::from_utf16(&dd.DeviceString) {
|
||||
if &s[..IDD_DEVICE_STRING.len()] == IDD_DEVICE_STRING {
|
||||
let ds = virtual_display_manager::get_cur_device_string();
|
||||
if let Ok(s) = String::from_utf16(&dd.DeviceString) {
|
||||
if s.len() >= ds.len() && &s[..ds.len()] == ds {
|
||||
self.virtual_displays.push(display);
|
||||
continue;
|
||||
}
|
||||
@@ -155,7 +157,7 @@ impl PrivacyModeImpl {
|
||||
}
|
||||
|
||||
fn restore_plug_out_monitor(&mut self) {
|
||||
let _ = virtual_display_manager::plug_out_peer_request(&self.virtual_displays_added);
|
||||
let _ = virtual_display_manager::plug_out_monitor_indices(&self.virtual_displays_added);
|
||||
self.virtual_displays_added.clear();
|
||||
}
|
||||
|
||||
@@ -304,8 +306,18 @@ impl PrivacyModeImpl {
|
||||
if self.virtual_displays.is_empty() {
|
||||
let displays =
|
||||
virtual_display_manager::plug_in_peer_request(vec![Self::default_display_modes()])?;
|
||||
self.virtual_displays_added.extend(displays);
|
||||
if virtual_display_manager::is_amyuni_idd() {
|
||||
thread::sleep(Duration::from_secs(3));
|
||||
}
|
||||
self.set_displays();
|
||||
|
||||
// No physical displays, no need to use the privacy mode.
|
||||
if self.displays.is_empty() {
|
||||
virtual_display_manager::plug_out_monitor_indices(&displays)?;
|
||||
bail!(NO_PHYSICAL_DISPLAYS);
|
||||
}
|
||||
|
||||
self.virtual_displays_added.extend(displays);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -348,6 +360,10 @@ impl PrivacyModeImpl {
|
||||
}
|
||||
|
||||
impl PrivacyMode for PrivacyModeImpl {
|
||||
fn is_async_privacy_mode(&self) -> bool {
|
||||
virtual_display_manager::is_amyuni_idd()
|
||||
}
|
||||
|
||||
fn init(&self) -> ResultType<()> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -367,8 +383,8 @@ impl PrivacyMode for PrivacyModeImpl {
|
||||
}
|
||||
self.set_displays();
|
||||
if self.displays.is_empty() {
|
||||
log::debug!("No displays");
|
||||
bail!(NO_DISPLAYS);
|
||||
log::debug!("{}", NO_PHYSICAL_DISPLAYS);
|
||||
bail!(NO_PHYSICAL_DISPLAYS);
|
||||
}
|
||||
|
||||
let mut guard = TurnOnGuard {
|
||||
@@ -379,7 +395,7 @@ impl PrivacyMode for PrivacyModeImpl {
|
||||
guard.ensure_virtual_display()?;
|
||||
if guard.virtual_displays.is_empty() {
|
||||
log::debug!("No virtual displays");
|
||||
bail!("No virtual displays");
|
||||
bail!("No virtual displays.");
|
||||
}
|
||||
|
||||
let reg_connectivity_1 = reg_display_settings::read_reg_connectivity()?;
|
||||
@@ -416,7 +432,7 @@ impl PrivacyMode for PrivacyModeImpl {
|
||||
self.check_off_conn_id(conn_id)?;
|
||||
super::win_input::unhook()?;
|
||||
self.restore();
|
||||
restore_reg_connectivity();
|
||||
restore_reg_connectivity(false);
|
||||
|
||||
if self.conn_id != INVALID_PRIVACY_MODE_CONN_ID {
|
||||
if let Some(state) = state {
|
||||
@@ -457,11 +473,14 @@ fn reset_config_reg_connectivity() {
|
||||
Config::set_option(CONFIG_KEY_REG_RECOVERY.to_owned(), "".to_owned());
|
||||
}
|
||||
|
||||
pub fn restore_reg_connectivity() {
|
||||
pub fn restore_reg_connectivity(plug_out_monitors: bool) {
|
||||
let config_recovery_value = Config::get_option(CONFIG_KEY_REG_RECOVERY);
|
||||
if config_recovery_value.is_empty() {
|
||||
return;
|
||||
}
|
||||
if plug_out_monitors {
|
||||
let _ = virtual_display_manager::plug_out_monitor(-1);
|
||||
}
|
||||
if let Ok(reg_recovery) =
|
||||
serde_json::from_str::<reg_display_settings::RegRecovery>(&config_recovery_value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user