win, clipboard, debug

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-06-19 22:06:08 +08:00
parent 2240853633
commit 5a8c2d9cd0
3 changed files with 13 additions and 14 deletions

View File

@ -7,24 +7,24 @@ lazy_static::lazy_static! {
}
pub struct ContextSend {
server_enabled: bool,
cm_enabled: bool,
addr: u64,
}
impl ContextSend {
fn new() -> Self {
Self {
server_enabled: false,
cm_enabled: false,
addr: 0,
}
}
#[inline]
pub fn is_server_enabled() -> bool {
CONTEXT_SEND.lock().unwrap().server_enabled
pub fn is_cm_enabled() -> bool {
CONTEXT_SEND.lock().unwrap().cm_enabled
}
pub fn enable(enabled: bool, is_server_side: bool, is_server_process: bool) {
pub fn enable(enabled: bool, is_cm_side: bool, is_server_process: bool) {
let mut lock = CONTEXT_SEND.lock().unwrap();
if enabled {
if lock.addr == 0 {
@ -41,8 +41,8 @@ impl ContextSend {
}
}
}
if is_server_side {
lock.server_enabled = true;
if is_cm_side {
lock.cm_enabled = true;
}
} else {
if lock.addr != 0 {
@ -53,7 +53,7 @@ impl ContextSend {
log::info!("clipboard context for file transfer destroyed.");
lock.addr = 0;
}
lock.server_enabled = false;
lock.cm_enabled = false;
}
}
}

View File

@ -439,10 +439,9 @@ impl Connection {
#[cfg(windows)]
ipc::Data::ClipboardFile(clip) => {
let is_stopping_allowed = clip.is_stopping_allowed();
let is_clipboard_enabled = clipboard::ContextSend::is_server_enabled();
let file_transfer_enabled = conn.file_transfer_enabled();
let stop = is_stopping_allowed && !(is_clipboard_enabled && file_transfer_enabled);
log::debug!("Process clipboard message from cm, stop: {}, is_stopping_allowed: {}, is_clipboard_enabled: {}, file_transfer_enabled: {}", stop, is_stopping_allowed, is_clipboard_enabled, file_transfer_enabled);
let stop = is_stopping_allowed && !file_transfer_enabled;
log::debug!("Process clipboard message from cm, stop: {}, is_stopping_allowed: {}, file_transfer_enabled: {}", stop, is_stopping_allowed, file_transfer_enabled);
if !stop {
allow_err!(conn.stream.send(&clip_2_msg(clip)).await);
}

View File

@ -336,7 +336,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
#[cfg(windows)]
{
if ContextSend::is_server_enabled() {
if ContextSend::is_cm_enabled() {
allow_err!(
self.stream
.send(&Data::ClipboardFile(clipboard::ClipboardFile::MonitorReady))
@ -402,7 +402,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
#[cfg(windows)]
{
let is_stopping_allowed = _clip.is_stopping_allowed();
let is_clipboard_enabled = ContextSend::is_server_enabled();
let is_clipboard_enabled = ContextSend::is_cm_enabled();
let file_transfer_enabled = self.file_transfer_enabled;
let stop = !is_stopping_allowed && !(is_clipboard_enabled && file_transfer_enabled);
log::debug!("Process clipboard message from peer, stop: {}, is_stopping_allowed: {}, is_clipboard_enabled: {}, file_transfer_enabled: {}", stop, is_stopping_allowed, is_clipboard_enabled, file_transfer_enabled);
@ -457,7 +457,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
#[cfg(windows)]
{
let is_stopping_allowed = _clip.is_stopping_allowed();
let is_clipboard_enabled = ContextSend::is_server_enabled();
let is_clipboard_enabled = ContextSend::is_cm_enabled();
let file_transfer_enabled = self.file_transfer_enabled;
let stop = is_stopping_allowed && !(is_clipboard_enabled && file_transfer_enabled);
log::debug!("Process clipboard message from cm, stop: {}, is_stopping_allowed: {}, is_clipboard_enabled: {}, file_transfer_enabled: {}", stop, is_stopping_allowed, is_clipboard_enabled, file_transfer_enabled);