remove session's old_clipboard
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
		
							parent
							
								
									9ebfe7f9ce
								
							
						
					
					
						commit
						e0f4cdd18c
					
				| @ -95,9 +95,10 @@ lazy_static::lazy_static! { | ||||
|     static ref TEXT_CLIPBOARD_STATE: Arc<Mutex<TextClipboardState>> = Arc::new(Mutex::new(TextClipboardState::new())); | ||||
| } | ||||
| 
 | ||||
| #[inline] | ||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
| pub fn update_clipboard_text(text: String) { | ||||
|     *OLD_CLIPBOARD_TEXT.lock().unwrap() = text; | ||||
| pub fn get_old_clipboard_text() -> &'static Arc<Mutex<String>> { | ||||
|     &OLD_CLIPBOARD_TEXT | ||||
| } | ||||
| 
 | ||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
| @ -666,16 +667,10 @@ impl Client { | ||||
| 
 | ||||
|                         if let Some(msg) = check_clipboard(&mut ctx, Some(&OLD_CLIPBOARD_TEXT)) { | ||||
|                             #[cfg(feature = "flutter")] | ||||
|                             crate::flutter::send_text_clipboard_msg( | ||||
|                                 &*OLD_CLIPBOARD_TEXT.lock().unwrap(), | ||||
|                                 msg, | ||||
|                             ); | ||||
|                             crate::flutter::send_text_clipboard_msg(msg); | ||||
|                             #[cfg(not(feature = "flutter"))] | ||||
|                             if let Some(ctx) = &_ctx { | ||||
|                                 if ctx.cfg.is_text_clipboard_required() | ||||
|                                     && *OLD_CLIPBOARD_TEXT.lock().unwrap() | ||||
|                                         != *ctx.old.lock().unwrap() | ||||
|                                 { | ||||
|                                 if ctx.cfg.is_text_clipboard_required() { | ||||
|                                     let _ = ctx.tx.send(Data::Message(msg)); | ||||
|                                 } | ||||
|                             } | ||||
| @ -2444,6 +2439,5 @@ pub(crate) struct ClientClipboardContext; | ||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
| pub(crate) struct ClientClipboardContext { | ||||
|     pub cfg: SessionPermissionConfig, | ||||
|     pub old: Arc<Mutex<String>>, | ||||
|     pub tx: UnboundedSender<Data>, | ||||
| } | ||||
|  | ||||
| @ -935,11 +935,12 @@ impl<T: InvokeUiSession> Remote<T> { | ||||
|                             Client::try_start_clipboard(None); | ||||
|                             #[cfg(not(feature = "flutter"))] | ||||
|                             #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|                             Client::try_start_clipboard(Some(crate::client::ClientClipboardContext { | ||||
|                                 cfg: permission_config.clone(), | ||||
|                                 old: self.handler.old_clipboard.clone(), | ||||
|                                 tx: sender.clone(), | ||||
|                             })); | ||||
|                             Client::try_start_clipboard(Some( | ||||
|                                 crate::client::ClientClipboardContext { | ||||
|                                     cfg: permission_config.clone(), | ||||
|                                     tx: sender.clone(), | ||||
|                                 }, | ||||
|                             )); | ||||
| 
 | ||||
|                             #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|                             tokio::spawn(async move { | ||||
| @ -972,7 +973,7 @@ impl<T: InvokeUiSession> Remote<T> { | ||||
|                 Some(message::Union::Clipboard(cb)) => { | ||||
|                     if !self.handler.lc.read().unwrap().disable_clipboard.v { | ||||
|                         #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|                         update_clipboard(cb, Some(&self.handler.old_clipboard)); | ||||
|                         update_clipboard(cb, Some(&crate::client::get_old_clipboard_text())); | ||||
|                         #[cfg(any(target_os = "android", target_os = "ios"))] | ||||
|                         { | ||||
|                             let content = if cb.compress { | ||||
|  | ||||
| @ -187,14 +187,9 @@ pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>) | ||||
|         } | ||||
|         match ClipboardContext::new() { | ||||
|             Ok(mut ctx) => { | ||||
|                 let host_side = "host"; | ||||
|                 let client_side = "client"; | ||||
|                 let side = if old.is_none() { host_side } else { client_side }; | ||||
|                 let side = if old.is_none() { "host" } else { "client" }; | ||||
|                 let old = if let Some(old) = old { old } else { &CONTENT }; | ||||
|                 *old.lock().unwrap() = content.clone(); | ||||
|                 if side == client_side { | ||||
|                     crate::client::update_clipboard_text(content.clone()); | ||||
|                 } | ||||
|                 let _lock = ARBOARD_MTX.lock().unwrap(); | ||||
|                 allow_err!(ctx.set_text(content)); | ||||
|                 log::debug!("{} updated on {}", CLIPBOARD_NAME, side); | ||||
|  | ||||
| @ -725,9 +725,9 @@ pub fn other_sessions_running(id: &str) -> bool { | ||||
| } | ||||
| 
 | ||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
| pub fn send_text_clipboard_msg(text: &str, msg: Message) { | ||||
| pub fn send_text_clipboard_msg(msg: Message) { | ||||
|     for (_id, session) in SESSIONS.read().unwrap().iter() { | ||||
|         if session.is_text_clipboard_required() && text != *session.old_clipboard.lock().unwrap() { | ||||
|         if session.is_text_clipboard_required() { | ||||
|             session.send(Data::Message(msg.clone())); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -43,8 +43,6 @@ pub struct Session<T: InvokeUiSession> { | ||||
|     pub server_keyboard_enabled: Arc<RwLock<bool>>, | ||||
|     pub server_file_transfer_enabled: Arc<RwLock<bool>>, | ||||
|     pub server_clipboard_enabled: Arc<RwLock<bool>>, | ||||
|     #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|     pub old_clipboard: Arc<Mutex<String>>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user