win, clipboard, debug
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
0094d306a8
commit
7740492fb0
@ -1,27 +1,19 @@
|
||||
use crate::cliprdr::*;
|
||||
use hbb_common::log;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref CONTEXT_SEND: Arc<Mutex<ContextSend>> = Arc::new(Mutex::new(ContextSend::new()));
|
||||
static ref CONTEXT_SEND: ContextSend = ContextSend{addr: Mutex::new(0)};
|
||||
}
|
||||
|
||||
pub struct ContextSend {
|
||||
cm_enabled: bool,
|
||||
addr: u64,
|
||||
addr: Mutex<u64>,
|
||||
}
|
||||
|
||||
impl ContextSend {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
cm_enabled: false,
|
||||
addr: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_cm_enabled() -> bool {
|
||||
CONTEXT_SEND.lock().unwrap().cm_enabled
|
||||
pub fn is_enabled() -> bool {
|
||||
*CONTEXT_SEND.addr.lock().unwrap() != 0
|
||||
}
|
||||
|
||||
pub fn set_is_stopped() {
|
||||
@ -31,14 +23,14 @@ impl ContextSend {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn enable(enabled: bool, is_cm_side: bool, is_server_process: bool) {
|
||||
let mut lock = CONTEXT_SEND.lock().unwrap();
|
||||
pub fn enable(enabled: bool) {
|
||||
let mut lock = CONTEXT_SEND.addr.lock().unwrap();
|
||||
if enabled {
|
||||
if lock.addr == 0 {
|
||||
if *lock == 0 {
|
||||
match crate::create_cliprdr_context(true, false) {
|
||||
Ok(context) => {
|
||||
log::info!("clipboard context for file transfer created.");
|
||||
lock.addr = Box::into_raw(context) as _;
|
||||
*lock = Box::into_raw(context) as _;
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
@ -48,28 +40,22 @@ impl ContextSend {
|
||||
}
|
||||
}
|
||||
}
|
||||
if is_cm_side {
|
||||
lock.cm_enabled = true;
|
||||
}
|
||||
} else {
|
||||
if lock.addr != 0 {
|
||||
if is_server_process {
|
||||
if *lock != 0 {
|
||||
unsafe {
|
||||
let _ = Box::from_raw(lock.addr as *mut CliprdrClientContext);
|
||||
let _ = Box::from_raw(*lock as *mut CliprdrClientContext);
|
||||
}
|
||||
log::info!("clipboard context for file transfer destroyed.");
|
||||
lock.addr = 0;
|
||||
}
|
||||
lock.cm_enabled = false;
|
||||
*lock = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn proc<F: FnOnce(&mut Box<CliprdrClientContext>) -> u32>(f: F) -> u32 {
|
||||
let lock = CONTEXT_SEND.lock().unwrap();
|
||||
if lock.addr != 0 {
|
||||
let lock = CONTEXT_SEND.addr.lock().unwrap();
|
||||
if *lock != 0 {
|
||||
unsafe {
|
||||
let mut context = Box::from_raw(lock.addr as *mut CliprdrClientContext);
|
||||
let mut context = Box::from_raw(*lock as *mut CliprdrClientContext);
|
||||
let code = f(&mut context);
|
||||
std::mem::forget(context);
|
||||
code
|
||||
|
@ -1550,7 +1550,7 @@ impl<T: InvokeUiSession> Remote<T> {
|
||||
{
|
||||
let enabled = *self.handler.server_file_transfer_enabled.read().unwrap()
|
||||
&& self.handler.lc.read().unwrap().enable_file_transfer.v;
|
||||
ContextSend::enable(enabled, false, false);
|
||||
ContextSend::enable(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
init_plugins(&args);
|
||||
if args.is_empty() {
|
||||
#[cfg(windows)]
|
||||
clipboard::ContextSend::enable(true, false, false);
|
||||
clipboard::ContextSend::enable(true);
|
||||
std::thread::spawn(move || crate::start_server(false));
|
||||
} else {
|
||||
#[cfg(windows)]
|
||||
|
@ -338,7 +338,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if ContextSend::is_cm_enabled() {
|
||||
if ContextSend::is_enabled() {
|
||||
allow_err!(
|
||||
self.stream
|
||||
.send(&Data::ClipboardFile(clipboard::ClipboardFile::MonitorReady))
|
||||
@ -404,7 +404,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let is_stopping_allowed = _clip.is_stopping_allowed_from_peer();
|
||||
let is_clipboard_enabled = ContextSend::is_cm_enabled();
|
||||
let is_clipboard_enabled = ContextSend::is_enabled();
|
||||
let file_transfer_enabled = self.file_transfer_enabled;
|
||||
let stop = !is_stopping_allowed && !(is_clipboard_enabled && file_transfer_enabled);
|
||||
log::debug!(
|
||||
@ -469,7 +469,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let is_stopping_allowed = _clip.is_stopping_allowed();
|
||||
let is_clipboard_enabled = ContextSend::is_cm_enabled();
|
||||
let is_clipboard_enabled = ContextSend::is_enabled();
|
||||
let file_transfer_enabled = self.file_transfer_enabled;
|
||||
let file_transfer_enabled_peer = self.file_transfer_enabled_peer;
|
||||
let stop = is_stopping_allowed && !(is_clipboard_enabled && file_transfer_enabled && file_transfer_enabled_peer);
|
||||
@ -537,11 +537,7 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
|
||||
});
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
ContextSend::enable(
|
||||
Config::get_option("enable-file-transfer").is_empty(),
|
||||
true,
|
||||
crate::is_server(),
|
||||
);
|
||||
ContextSend::enable(Config::get_option("enable-file-transfer").is_empty());
|
||||
|
||||
match ipc::new_listener("_cm").await {
|
||||
Ok(mut incoming) => {
|
||||
|
@ -882,11 +882,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
|
||||
{
|
||||
let b = OPTIONS.lock().unwrap().get("enable-file-transfer").map(|x| x.to_string()).unwrap_or_default();
|
||||
if b != enable_file_transfer {
|
||||
clipboard::ContextSend::enable(
|
||||
b.is_empty(),
|
||||
true,
|
||||
crate::is_server(),
|
||||
);
|
||||
clipboard::ContextSend::enable(b.is_empty());
|
||||
enable_file_transfer = b;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user