remove Instant sub (#8714)

which cause crash when connect to windows just startup

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2024-07-15 10:49:09 +08:00 committed by GitHub
parent 8512c2b2b0
commit 3f11d9cdb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 10 deletions

View File

@ -283,7 +283,7 @@ async fn handle_received_peers(mut rx: UnboundedReceiver<config::DiscoveryPeer>)
});
let mut response_set = HashSet::new();
let mut last_write_time = Instant::now() - std::time::Duration::from_secs(4);
let mut last_write_time: Option<Instant> = None;
loop {
tokio::select! {
data = rx.recv() => match data {
@ -297,11 +297,11 @@ async fn handle_received_peers(mut rx: UnboundedReceiver<config::DiscoveryPeer>)
}
}
peers.insert(0, peer);
if last_write_time.elapsed().as_millis() > 300 {
if last_write_time.map(|t| t.elapsed().as_millis() > 300).unwrap_or(true) {
config::LanPeers::store(&peers);
#[cfg(feature = "flutter")]
crate::flutter_ffi::main_load_lan_peers();
last_write_time = Instant::now();
last_write_time = Some(Instant::now());
}
}
None => {

View File

@ -312,7 +312,7 @@ pub fn new_window_focus() -> GenericService {
fn update_last_cursor_pos(x: i32, y: i32) {
let mut lock = LATEST_SYS_CURSOR_POS.lock().unwrap();
if lock.1 .0 != x || lock.1 .1 != y {
(lock.0, lock.1) = (Instant::now(), (x, y))
(lock.0, lock.1) = (Some(Instant::now()), (x, y))
}
}
@ -411,7 +411,7 @@ lazy_static::lazy_static! {
};
static ref KEYS_DOWN: Arc<Mutex<HashMap<KeysDown, Instant>>> = Default::default();
static ref LATEST_PEER_INPUT_CURSOR: Arc<Mutex<Input>> = Default::default();
static ref LATEST_SYS_CURSOR_POS: Arc<Mutex<(Instant, (i32, i32))>> = Arc::new(Mutex::new((Instant::now().sub(MOUSE_MOVE_PROTECTION_TIMEOUT), (INVALID_CURSOR_POS, INVALID_CURSOR_POS))));
static ref LATEST_SYS_CURSOR_POS: Arc<Mutex<(Option<Instant>, (i32, i32))>> = Arc::new(Mutex::new((None, (INVALID_CURSOR_POS, INVALID_CURSOR_POS))));
}
static EXITING: AtomicBool = AtomicBool::new(false);
@ -808,7 +808,13 @@ fn active_mouse_(conn: i32) -> bool {
true
/* this method is buggy (not working on macOS, making fast moving mouse event discarded here) and added latency (this is blocking way, must do in async way), so we disable it for now
// out of time protection
if LATEST_SYS_CURSOR_POS.lock().unwrap().0.elapsed() > MOUSE_MOVE_PROTECTION_TIMEOUT {
if LATEST_SYS_CURSOR_POS
.lock()
.unwrap()
.0
.map(|t| t.elapsed() > MOUSE_MOVE_PROTECTION_TIMEOUT)
.unwrap_or(true)
{
return true;
}

View File

@ -428,7 +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))));
static ref LAST_PLUG_IN_HEADLESS_TIME: Arc<Mutex<Option<Instant>>> = Arc::new(Mutex::new(None));
}
fn get_deviceinstaller64_work_dir() -> ResultType<Option<Vec<u8>>> {
@ -573,10 +573,12 @@ pub mod amyuni_idd {
pub fn plug_in_headless() -> ResultType<()> {
let mut tm = LAST_PLUG_IN_HEADLESS_TIME.lock().unwrap();
if tm.elapsed() < Duration::from_secs(3) {
bail!("Plugging in too frequently.");
if let Some(tm) = &mut *tm {
if tm.elapsed() < Duration::from_secs(3) {
bail!("Plugging in too frequently.");
}
}
*tm = Instant::now();
*tm = Some(Instant::now());
drop(tm);
let mut is_async = false;