Merge pull request #3997 from fufesou/fix/clipboard_chain_update
fix chain update
This commit is contained in:
commit
72beb088cf
@ -95,6 +95,12 @@ lazy_static::lazy_static! {
|
|||||||
static ref TEXT_CLIPBOARD_STATE: Arc<Mutex<TextClipboardState>> = Arc::new(Mutex::new(TextClipboardState::new()));
|
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 get_old_clipboard_text() -> &'static Arc<Mutex<String>> {
|
||||||
|
&OLD_CLIPBOARD_TEXT
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub fn get_key_state(key: enigo::Key) -> bool {
|
pub fn get_key_state(key: enigo::Key) -> bool {
|
||||||
use enigo::KeyboardControllable;
|
use enigo::KeyboardControllable;
|
||||||
@ -635,8 +641,13 @@ impl Client {
|
|||||||
TEXT_CLIPBOARD_STATE.lock().unwrap().running = false;
|
TEXT_CLIPBOARD_STATE.lock().unwrap().running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `try_start_clipboard` is called by all session when connection is established. (When handling peer info).
|
||||||
|
// This function only create one thread with a loop, the loop is shared by all sessions.
|
||||||
|
// After all sessions are end, the loop exists.
|
||||||
|
//
|
||||||
|
// If clipboard update is detected, the text will be sent to all sessions by `send_text_clipboard_msg`.
|
||||||
#[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<ClientClipboardContext>) {
|
fn try_start_clipboard(_ctx: 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;
|
||||||
@ -661,16 +672,10 @@ 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(
|
crate::flutter::send_text_clipboard_msg(msg);
|
||||||
&*OLD_CLIPBOARD_TEXT.lock().unwrap(),
|
|
||||||
msg,
|
|
||||||
);
|
|
||||||
#[cfg(not(feature = "flutter"))]
|
#[cfg(not(feature = "flutter"))]
|
||||||
if let Some(ctx) = &_ctx {
|
if let Some(ctx) = &_ctx {
|
||||||
if ctx.cfg.is_text_clipboard_required()
|
if ctx.cfg.is_text_clipboard_required() {
|
||||||
&& *OLD_CLIPBOARD_TEXT.lock().unwrap()
|
|
||||||
!= *ctx.old.lock().unwrap()
|
|
||||||
{
|
|
||||||
let _ = ctx.tx.send(Data::Message(msg));
|
let _ = ctx.tx.send(Data::Message(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2439,6 +2444,5 @@ pub(crate) struct ClientClipboardContext;
|
|||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub(crate) struct ClientClipboardContext {
|
pub(crate) struct ClientClipboardContext {
|
||||||
pub cfg: SessionPermissionConfig,
|
pub cfg: SessionPermissionConfig,
|
||||||
pub old: Arc<Mutex<String>>,
|
|
||||||
pub tx: UnboundedSender<Data>,
|
pub tx: UnboundedSender<Data>,
|
||||||
}
|
}
|
||||||
|
@ -935,11 +935,12 @@ 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(ClientClipboardContext {
|
Client::try_start_clipboard(Some(
|
||||||
|
crate::client::ClientClipboardContext {
|
||||||
cfg: permission_config.clone(),
|
cfg: permission_config.clone(),
|
||||||
old: self.handler.old_clipboard.clone(),
|
|
||||||
tx: sender.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 {
|
||||||
@ -972,7 +973,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.handler.old_clipboard));
|
update_clipboard(cb, Some(&crate::client::get_old_clipboard_text()));
|
||||||
#[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(text: &str, msg: Message) {
|
pub fn send_text_clipboard_msg(msg: Message) {
|
||||||
for (_id, session) in SESSIONS.read().unwrap().iter() {
|
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()));
|
session.send(Data::Message(msg.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,6 @@ 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