Merge pull request #3995 from fufesou/fix/text_clipboard
Fix/text clipboard
This commit is contained in:
commit
a767df185f
@ -24,6 +24,7 @@ use sha2::{Digest, Sha256};
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub use file_trait::FileManager;
|
pub use file_trait::FileManager;
|
||||||
|
#[cfg(not(feature = "flutter"))]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
use hbb_common::tokio::sync::mpsc::UnboundedSender;
|
use hbb_common::tokio::sync::mpsc::UnboundedSender;
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
@ -58,10 +59,10 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
use crate::{
|
use crate::common::{check_clipboard, ClipboardContext, CLIPBOARD_INTERVAL};
|
||||||
common::{check_clipboard, ClipboardContext, CLIPBOARD_INTERVAL},
|
#[cfg(not(feature = "flutter"))]
|
||||||
ui_session_interface::SessionPermissionConfig,
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
};
|
use crate::ui_session_interface::SessionPermissionConfig;
|
||||||
|
|
||||||
pub use super::lang::*;
|
pub use super::lang::*;
|
||||||
|
|
||||||
@ -635,7 +636,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
fn try_start_clipboard(_conf_tx: Option<(SessionPermissionConfig, UnboundedSender<Data>)>) {
|
fn try_start_clipboard(_conf_tx: Option<ClientClipboardContext>) {
|
||||||
let mut clipboard_lock = TEXT_CLIPBOARD_STATE.lock().unwrap();
|
let mut clipboard_lock = TEXT_CLIPBOARD_STATE.lock().unwrap();
|
||||||
if clipboard_lock.running {
|
if clipboard_lock.running {
|
||||||
return;
|
return;
|
||||||
@ -660,11 +661,17 @@ impl Client {
|
|||||||
|
|
||||||
if let Some(msg) = check_clipboard(&mut ctx, Some(&OLD_CLIPBOARD_TEXT)) {
|
if let Some(msg) = check_clipboard(&mut ctx, Some(&OLD_CLIPBOARD_TEXT)) {
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
crate::flutter::send_text_clipboard_msg(msg);
|
crate::flutter::send_text_clipboard_msg(
|
||||||
|
&*OLD_CLIPBOARD_TEXT.lock().unwrap(),
|
||||||
|
msg,
|
||||||
|
);
|
||||||
#[cfg(not(feature = "flutter"))]
|
#[cfg(not(feature = "flutter"))]
|
||||||
if let Some((cfg, tx)) = &_conf_tx {
|
if let Some(ctx) = &_ctx {
|
||||||
if cfg.is_text_clipboard_required() {
|
if ctx.cfg.is_text_clipboard_required()
|
||||||
let _ = tx.send(Data::Message(msg));
|
&& *OLD_CLIPBOARD_TEXT.lock().unwrap()
|
||||||
|
!= *ctx.old.lock().unwrap()
|
||||||
|
{
|
||||||
|
let _ = ctx.tx.send(Data::Message(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2423,3 +2430,15 @@ fn decode_id_pk(signed: &[u8], key: &sign::PublicKey) -> ResultType<(String, [u8
|
|||||||
bail!("Wrong public length");
|
bail!("Wrong public length");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "flutter")]
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
pub(crate) struct ClientClipboardContext;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "flutter"))]
|
||||||
|
#[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>,
|
||||||
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::num::NonZeroI64;
|
use std::num::NonZeroI64;
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
@ -51,8 +49,6 @@ pub struct Remote<T: InvokeUiSession> {
|
|||||||
// Stop sending local audio to remote client.
|
// Stop sending local audio to remote client.
|
||||||
stop_voice_call_sender: Option<std::sync::mpsc::Sender<()>>,
|
stop_voice_call_sender: Option<std::sync::mpsc::Sender<()>>,
|
||||||
voice_call_request_timestamp: Option<NonZeroI64>,
|
voice_call_request_timestamp: Option<NonZeroI64>,
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
old_clipboard: Arc<Mutex<String>>,
|
|
||||||
read_jobs: Vec<fs::TransferJob>,
|
read_jobs: Vec<fs::TransferJob>,
|
||||||
write_jobs: Vec<fs::TransferJob>,
|
write_jobs: Vec<fs::TransferJob>,
|
||||||
remove_jobs: HashMap<i32, RemoveJob>,
|
remove_jobs: HashMap<i32, RemoveJob>,
|
||||||
@ -87,8 +83,6 @@ impl<T: InvokeUiSession> Remote<T> {
|
|||||||
audio_sender,
|
audio_sender,
|
||||||
receiver,
|
receiver,
|
||||||
sender,
|
sender,
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
old_clipboard: Default::default(),
|
|
||||||
read_jobs: Vec::new(),
|
read_jobs: Vec::new(),
|
||||||
write_jobs: Vec::new(),
|
write_jobs: Vec::new(),
|
||||||
remove_jobs: Default::default(),
|
remove_jobs: Default::default(),
|
||||||
@ -941,10 +935,11 @@ impl<T: InvokeUiSession> Remote<T> {
|
|||||||
Client::try_start_clipboard(None);
|
Client::try_start_clipboard(None);
|
||||||
#[cfg(not(feature = "flutter"))]
|
#[cfg(not(feature = "flutter"))]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
Client::try_start_clipboard(Some((
|
Client::try_start_clipboard(Some(ClientClipboardContext {
|
||||||
permission_config.clone(),
|
cfg: permission_config.clone(),
|
||||||
sender.clone(),
|
old: self.handler.old_clipboard.clone(),
|
||||||
)));
|
tx: sender.clone(),
|
||||||
|
}));
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
@ -977,7 +972,7 @@ impl<T: InvokeUiSession> Remote<T> {
|
|||||||
Some(message::Union::Clipboard(cb)) => {
|
Some(message::Union::Clipboard(cb)) => {
|
||||||
if !self.handler.lc.read().unwrap().disable_clipboard.v {
|
if !self.handler.lc.read().unwrap().disable_clipboard.v {
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
update_clipboard(cb, Some(&self.old_clipboard));
|
update_clipboard(cb, Some(&self.handler.old_clipboard));
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
{
|
{
|
||||||
let content = if cb.compress {
|
let content = if cb.compress {
|
||||||
|
@ -725,9 +725,9 @@ pub fn other_sessions_running(id: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub fn send_text_clipboard_msg(msg: Message) {
|
pub fn send_text_clipboard_msg(text: &str, msg: Message) {
|
||||||
for (_id, session) in SESSIONS.read().unwrap().iter() {
|
for (_id, session) in SESSIONS.read().unwrap().iter() {
|
||||||
if session.is_text_clipboard_required() {
|
if session.is_text_clipboard_required() && text != *session.old_clipboard.lock().unwrap() {
|
||||||
session.send(Data::Message(msg.clone()));
|
session.send(Data::Message(msg.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ pub struct Session<T: InvokeUiSession> {
|
|||||||
pub server_keyboard_enabled: Arc<RwLock<bool>>,
|
pub server_keyboard_enabled: Arc<RwLock<bool>>,
|
||||||
pub server_file_transfer_enabled: Arc<RwLock<bool>>,
|
pub server_file_transfer_enabled: Arc<RwLock<bool>>,
|
||||||
pub server_clipboard_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)]
|
#[derive(Clone)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user