tmp commit

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-06-29 18:12:34 +08:00
parent aaca56c1f8
commit 1f71dc979c
10 changed files with 89 additions and 112 deletions

View File

@ -168,7 +168,7 @@ extern "C"
typedef UINT (*pcCliprdrTempDirectory)(CliprdrClientContext *context,
const CLIPRDR_TEMP_DIRECTORY *tempDirectory);
typedef UINT (*pcNotifyClipboardMsg)(const NOTIFICATION_MESSAGE *msg);
typedef UINT (*pcNotifyClipboardMsg)(UINT32 connID, const NOTIFICATION_MESSAGE *msg);
typedef UINT (*pcCliprdrClientFormatList)(CliprdrClientContext *context,
const CLIPRDR_FORMAT_LIST *formatList);

View File

@ -357,7 +357,7 @@ pub type pcCliprdrTempDirectory = ::std::option::Option<
) -> UINT,
>;
pub type pcNotifyClipboardMsg =
::std::option::Option<unsafe extern "C" fn(msg: *const NOTIFICATION_MESSAGE) -> UINT>;
::std::option::Option<unsafe extern "C" fn(connID: UINT32, msg: *const NOTIFICATION_MESSAGE) -> UINT>;
pub type pcCliprdrClientFormatList = ::std::option::Option<
unsafe extern "C" fn(
context: *mut CliprdrClientContext,

View File

@ -2,7 +2,7 @@ use crate::cliprdr::*;
use hbb_common::log;
use std::sync::Mutex;
const CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS: u32 = 30;
const CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS: u32 = 0;
lazy_static::lazy_static! {
static ref CONTEXT_SEND: ContextSend = ContextSend{addr: Mutex::new(0)};

View File

@ -21,15 +21,14 @@ pub use context_send::*;
const ERR_CODE_SERVER_FUNCTION_NONE: u32 = 0x00000001;
const ERR_CODE_INVALID_PARAMETER: u32 = 0x00000002;
pub type FnNotifyCallback = fn(r#type: u32, msg: &str, details: &str) -> u32;
lazy_static::lazy_static! {
static ref NOTIFY_CALLBACK: Arc<Mutex<Option<FnNotifyCallback>>> = Default::default();
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "t", content = "c")]
pub enum ClipboardFile {
NotifyCallback {
r#type: String,
title: String,
text: String,
},
MonitorReady,
FormatList {
format_list: Vec<(i32, String)>,
@ -174,41 +173,40 @@ pub fn server_clip_file(
conn_id: i32,
msg: ClipboardFile,
) -> u32 {
let mut ret = 0;
match msg {
ClipboardFile::NotifyCallback { .. } => {
// unreachable
}
ClipboardFile::MonitorReady => {
log::debug!("server_monitor_ready called");
let ret = server_monitor_ready(context, conn_id);
ret = server_monitor_ready(context, conn_id);
log::debug!("server_monitor_ready called, return {}", ret);
ret
}
ClipboardFile::FormatList { format_list } => {
log::debug!("server_format_list called");
let ret = server_format_list(context, conn_id, format_list);
ret = server_format_list(context, conn_id, format_list);
log::debug!("server_format_list called, return {}", ret);
ret
}
ClipboardFile::FormatListResponse { msg_flags } => {
log::debug!("format_list_response called");
let ret = server_format_list_response(context, conn_id, msg_flags);
ret = server_format_list_response(context, conn_id, msg_flags);
log::debug!("server_format_list_response called, return {}", ret);
ret
}
ClipboardFile::FormatDataRequest {
requested_format_id,
} => {
log::debug!("format_data_request called");
let ret = server_format_data_request(context, conn_id, requested_format_id);
ret = server_format_data_request(context, conn_id, requested_format_id);
log::debug!("server_format_data_request called, return {}", ret);
ret
}
ClipboardFile::FormatDataResponse {
msg_flags,
format_data,
} => {
log::debug!("format_data_response called");
let ret = server_format_data_response(context, conn_id, msg_flags, format_data);
ret = server_format_data_response(context, conn_id, msg_flags, format_data);
log::debug!("server_format_data_response called, return {}", ret);
ret
}
ClipboardFile::FileContentsRequest {
stream_id,
@ -221,7 +219,7 @@ pub fn server_clip_file(
clip_data_id,
} => {
log::debug!("file_contents_request called");
let ret = server_file_contents_request(
ret = server_file_contents_request(
context,
conn_id,
stream_id,
@ -234,7 +232,6 @@ pub fn server_clip_file(
clip_data_id,
);
log::debug!("server_file_contents_request called, return {}", ret);
ret
}
ClipboardFile::FileContentsResponse {
msg_flags,
@ -242,7 +239,7 @@ pub fn server_clip_file(
requested_data,
} => {
log::debug!("file_contents_response called");
let ret = server_file_contents_response(
ret = server_file_contents_response(
context,
conn_id,
msg_flags,
@ -250,10 +247,10 @@ pub fn server_clip_file(
requested_data,
);
log::debug!("server_file_contents_response called, return {}", ret);
}
}
ret
}
}
}
pub fn server_monitor_ready(context: &mut Box<CliprdrClientContext>, conn_id: i32) -> u32 {
unsafe {
@ -469,14 +466,9 @@ pub fn create_cliprdr_context(
)?)
}
pub fn set_notify_callback(cb: FnNotifyCallback) {
NOTIFY_CALLBACK.lock().unwrap().replace(cb);
}
extern "C" fn notify_callback(msg: *const NOTIFICATION_MESSAGE) -> UINT {
extern "C" fn notify_callback(conn_id: UINT32, msg: *const NOTIFICATION_MESSAGE) -> UINT {
log::debug!("notify_callback called");
if let Some(cb) = NOTIFY_CALLBACK.lock().unwrap().as_ref() {
unsafe {
let data = unsafe {
let msg = &*msg;
let details = if msg.details.is_null() {
Ok("")
@ -484,16 +476,35 @@ extern "C" fn notify_callback(msg: *const NOTIFICATION_MESSAGE) -> UINT {
CStr::from_ptr(msg.details as _).to_str()
};
match (CStr::from_ptr(msg.msg as _).to_str(), details) {
(Ok(m), Ok(d)) => cb(msg.r#type, m, d),
(Ok(m), Ok(d)) => {
let msgtype = format!(
"{}-nocancel-nook-hasclose",
if msg.r#type == 0 {
"info"
} else if msg.r#type == 1 {
"warn"
} else {
"error"
}
);
let title = "Clipboard";
let text = format!("{}: {}", m, d);
ClipboardFile::NotifyCallback {
r#type: msgtype,
title: title.to_string(),
text,
}
}
_ => {
log::error!("notify_callback: failed to convert msg");
ERR_CODE_INVALID_PARAMETER
return ERR_CODE_INVALID_PARAMETER;
}
}
}
} else {
ERR_CODE_SERVER_FUNCTION_NONE
}
};
// no need to handle result here
send_data(conn_id as _, data);
0
}
extern "C" fn client_format_list(

View File

@ -1449,7 +1449,7 @@ static UINT cliprdr_send_format_list(wfClipboard *clipboard, UINT32 connID)
return rc;
}
UINT wait_response_event(wfClipboard *clipboard, HANDLE event, void **data)
UINT wait_response_event(UINT32 connID, wfClipboard *clipboard, HANDLE event, void **data)
{
UINT rc = ERROR_SUCCESS;
clipboard->context->IsStopped = FALSE;
@ -1495,7 +1495,7 @@ UINT wait_response_event(wfClipboard *clipboard, HANDLE event, void **data)
msg.type = 2;
msg.msg = "clipboard_wait_response_timeout_tip";
msg.details = NULL;
clipboard->context->NotifyClipboardMsg(&msg);
clipboard->context->NotifyClipboardMsg(connID, &msg);
rc = ERROR_INTERNAL_ERROR;
if (!ResetEvent(event))
@ -1535,7 +1535,7 @@ static UINT cliprdr_send_data_request(UINT32 connID, wfClipboard *clipboard, UIN
return rc;
}
wait_response_event(clipboard, clipboard->response_data_event, &clipboard->hmem);
wait_response_event(connID, clipboard, clipboard->response_data_event, &clipboard->hmem);
}
UINT cliprdr_send_request_filecontents(wfClipboard *clipboard, UINT32 connID, const void *streamid, ULONG index,
@ -1563,7 +1563,7 @@ UINT cliprdr_send_request_filecontents(wfClipboard *clipboard, UINT32 connID, co
return rc;
}
return wait_response_event(clipboard, clipboard->req_fevent, (void **)&clipboard->req_fdata);
return wait_response_event(connID, clipboard, clipboard->req_fevent, (void **)&clipboard->req_fdata);
}
static UINT cliprdr_send_response_filecontents(

View File

@ -206,7 +206,11 @@ impl<T: InvokeUiSession> Remote<T> {
_msg = rx_clip_client.recv() => {
#[cfg(windows)]
match _msg {
Some(clip) => {
Some(clip) => match clip {
clipboard::ClipboardFile::NotifyCallback{r#type, title, text} => {
self.handler.msgbox(&r#type, &title, &text, "");
}
_ => {
let is_stopping_allowed = clip.is_stopping_allowed();
let server_file_transfer_enabled = *self.handler.server_file_transfer_enabled.read().unwrap();
let file_transfer_enabled = self.handler.lc.read().unwrap().enable_file_transfer.v;
@ -218,6 +222,7 @@ impl<T: InvokeUiSession> Remote<T> {
allow_err!(peer.send(&crate::clipboard_file::clip_2_msg(clip)).await);
}
}
}
None => {
// unreachable!()
}

View File

@ -3,6 +3,20 @@ use hbb_common::message_proto::*;
pub fn clip_2_msg(clip: ClipboardFile) -> Message {
match clip {
ClipboardFile::NotifyCallback {
r#type,
title,
text,
} => Message {
union: Some(message::Union::MessageBox(MessageBox {
msgtype: r#type,
title,
text,
link: "".to_string(),
..Default::default()
})),
..Default::default()
},
ClipboardFile::MonitorReady => Message {
union: Some(message::Union::Cliprdr(Cliprdr {
union: Some(cliprdr::Union::Ready(CliprdrMonitorReady {

View File

@ -13,8 +13,6 @@ use hbb_common::platform::register_breakdown_handler;
/// If it returns [`Some`], then the process will continue, and flutter gui will be started.
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn core_main() -> Option<Vec<String>> {
use crate::flutter;
let mut args = Vec::new();
let mut flutter_args = Vec::new();
let mut i = 0;
@ -127,14 +125,6 @@ pub fn core_main() -> Option<Vec<String>> {
#[cfg(windows)]
{
clipboard::ContextSend::enable(true);
#[cfg(feature = "flutter")]
{
clipboard::set_notify_callback(flutter::msgbox_clipboard_remote);
}
#[cfg(not(feature = "flutter"))]
{
// notify callback for non-flutter is not supported.
}
}
std::thread::spawn(move || crate::start_server(false));
} else {

View File

@ -1089,41 +1089,6 @@ pub fn stop_global_event_stream(app_type: String) {
let _ = GLOBAL_EVENT_STREAM.write().unwrap().remove(&app_type);
}
fn msgbox_clipboard_(channel: &str, r#type: u32, msg: &str, details: &str) -> u32 {
let msgtype = format!(
"{}-nocancel-nook-hasclose",
if r#type == 0 {
"info"
} else if r#type == 1 {
"warn"
} else {
"error"
}
);
let text = format!("{} {}", msg, details);
if let Ok(event) = serde_json::ser::to_string(&HashMap::from([
("name", "msgbox"),
("type", &msgtype as &str),
("title", "clipboard"),
("text", &text),
("link", ""),
("hasRetry", ""),
])) {
push_global_event(channel, event);
}
0
}
#[inline]
pub fn msgbox_clipboard_remote(r#type: u32, msg: &str, details: &str) -> u32 {
msgbox_clipboard_(APP_TYPE_DESKTOP_REMOTE, r#type, msg, details)
}
#[inline]
pub fn msgbox_clipboard_cm(r#type: u32, msg: &str, details: &str) -> u32 {
msgbox_clipboard_(APP_TYPE_CM, r#type, msg, details)
}
#[no_mangle]
unsafe extern "C" fn get_rgba() {}

View File

@ -538,14 +538,6 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
#[cfg(target_os = "windows")]
ContextSend::enable(Config::get_option("enable-file-transfer").is_empty());
#[cfg(feature = "flutter")]
{
clipboard::set_notify_callback(crate::flutter::msgbox_clipboard_cm);
}
#[cfg(not(feature = "flutter"))]
{
// notify callback for non-flutter is not supported.
}
match ipc::new_listener("_cm").await {
Ok(mut incoming) => {