From b5a88d00af3670872ac17dcdcc93387abfc1e70e Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 6 May 2024 13:34:31 +0800 Subject: [PATCH] fix: headless, plug in multiple virtual displays (#7912) Signed-off-by: fufesou --- src/virtual_display_manager.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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> = Default::default(); + static ref LAST_PLUG_IN_HEADLESS_TIME: Arc> = Arc::new(Mutex::new(Instant::now().sub(Duration::from_secs(100)))); } fn get_deviceinstaller64_work_dir() -> ResultType>> { @@ -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) {