diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 8316139a5..78949b0b5 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -68,7 +68,6 @@ struct IpcTaskRunner { rx: mpsc::UnboundedReceiver, close: bool, running: bool, - authorized: bool, conn_id: i32, #[cfg(windows)] file_transfer_enabled: bool, @@ -162,6 +161,16 @@ impl ConnectionManager { self.ui_handler.add_connection(&client); } + #[inline] + fn is_authorized(&self, id: i32) -> bool { + CLIENTS + .read() + .unwrap() + .get(&id) + .map(|c| c.authorized) + .unwrap_or(false) + } + fn remove_connection(&self, id: i32, close: bool) { if close { CLIENTS.write().unwrap().remove(&id); @@ -316,13 +325,14 @@ impl IpcTaskRunner { // for tmp use, without real conn id let mut write_jobs: Vec = Vec::new(); + let is_authorized = self.cm.is_authorized(self.conn_id); #[cfg(windows)] let rx_clip1; let mut rx_clip; let _tx_clip; #[cfg(windows)] - if self.conn_id > 0 && self.authorized { + if is_authorized { rx_clip1 = clipboard::get_rx_cliprdr_server(self.conn_id); rx_clip = rx_clip1.lock().await; } else { @@ -361,7 +371,6 @@ impl IpcTaskRunner { Data::Login{id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, file_transfer_enabled: _file_transfer_enabled, restart, recording, from_switch} => { log::debug!("conn_id: {}", id); self.cm.add_connection(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, restart, recording, from_switch,self.tx.clone()); - self.authorized = authorized; self.conn_id = id; #[cfg(windows)] { @@ -413,7 +422,7 @@ impl IpcTaskRunner { if stop { ContextSend::set_is_stopped(); } else { - if !self.authorized { + if !is_authorized { log::debug!("Clipboard message from client peer, but not authorized"); continue; } @@ -469,7 +478,6 @@ impl IpcTaskRunner { } } Data::Authorize => { - self.authorized = true; self.running = true; break; } @@ -514,7 +522,6 @@ impl IpcTaskRunner { rx, close: true, running: true, - authorized: false, conn_id: 0, #[cfg(windows)] file_transfer_enabled: false,