Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: headless, plug in multiple virtual displays (#7912)

fufesoub5a88d00af36
diff --git a/src/virtual_display_manager.rs b/src/virtual_display_manager.rs
index 72a39a987..f03121967 100644
--- a/src/virtual_display_manager.rs
+++ b/src/virtual_display_manager.rs
@@ -405,6 +405,7 @@ pub mod amyuni_idd {
use crate::platform::win_device;
use hbb_common::{bail, lazy_static, log, tokio::time::Instant, ResultType};
use std::{
+ ops::Sub,
ptr::null_mut,
sync::{Arc, Mutex},
time::Duration,
@@ -427,6 +428,7 @@ pub mod amyuni_idd {
lazy_static::lazy_static! {
static ref LOCK: Arc<Mutex<()>> = Default::default();
+ static ref LAST_PLUG_IN_HEADLESS_TIME: Arc<Mutex<Instant>> = Arc::new(Mutex::new(Instant::now().sub(Duration::from_secs(100))));
}
fn get_deviceinstaller64_work_dir() -> ResultType<Option<Vec<u8>>> {
@@ -570,9 +572,12 @@ pub mod amyuni_idd {
}
pub fn plug_in_headless() -> ResultType<()> {
- if get_monitor_count() > 0 {
- return Ok(());
+ let mut tm = LAST_PLUG_IN_HEADLESS_TIME.lock().unwrap();
+ if tm.elapsed() < Duration::from_secs(3) {
+ bail!("Plugging in too frequently.");
}
+ *tm = Instant::now();
+ drop(tm);
let mut is_async = false;
if let Err(e) = check_install_driver(&mut is_async) {