From 152da86665b422315d826ed28a39ac180dffc298 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 10:14:17 +0800 Subject: [PATCH 01/12] win, clipbord, ResponseWaitTimeoutSecs Signed-off-by: dignow --- libs/clipboard/src/cliprdr.h | 1 + libs/clipboard/src/cliprdr.rs | 2 ++ libs/clipboard/src/windows/wf_cliprdr.c | 7 ++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/clipboard/src/cliprdr.h b/libs/clipboard/src/cliprdr.h index 57cae5f8f..9d56049ee 100644 --- a/libs/clipboard/src/cliprdr.h +++ b/libs/clipboard/src/cliprdr.h @@ -199,6 +199,7 @@ extern "C" BOOL EnableOthers; BOOL IsStopped; + UINT32 ResponseWaitTimeoutSecs; pcCliprdrServerCapabilities ServerCapabilities; pcCliprdrClientCapabilities ClientCapabilities; pcCliprdrMonitorReady MonitorReady; diff --git a/libs/clipboard/src/cliprdr.rs b/libs/clipboard/src/cliprdr.rs index e5bc3e7ef..6bbb27ca0 100644 --- a/libs/clipboard/src/cliprdr.rs +++ b/libs/clipboard/src/cliprdr.rs @@ -453,6 +453,7 @@ pub struct _cliprdr_client_context { pub EnableFiles: BOOL, pub EnableOthers: BOOL, pub IsStopped: BOOL, + pub ResponseWaitTimeoutSecs: UINT32, pub ServerCapabilities: pcCliprdrServerCapabilities, pub ClientCapabilities: pcCliprdrClientCapabilities, pub MonitorReady: pcCliprdrMonitorReady, @@ -510,6 +511,7 @@ impl CliprdrClientContext { EnableFiles: if enable_files { TRUE } else { FALSE }, EnableOthers: if enable_others { TRUE } else { FALSE }, IsStopped: FALSE, + ResponseWaitTimeoutSecs: 60, ServerCapabilities: None, ClientCapabilities: None, MonitorReady: None, diff --git a/libs/clipboard/src/windows/wf_cliprdr.c b/libs/clipboard/src/windows/wf_cliprdr.c index f7111c41b..ea582d5b1 100644 --- a/libs/clipboard/src/windows/wf_cliprdr.c +++ b/libs/clipboard/src/windows/wf_cliprdr.c @@ -1453,10 +1453,11 @@ UINT wait_response_event(wfClipboard *clipboard, HANDLE event, void **data) { UINT rc = ERROR_SUCCESS; clipboard->context->IsStopped = FALSE; - // with default 3min timeout - for (int i = 0; i < 20 * 60 * 3; i++) + DWORD waitOnceTimeoutMillis = 50; + int waitCount = 1000 * clipboard->context->ResponseWaitTimeoutSecs / waitOnceTimeoutMillis; + for (int i = 0; i < waitCount * 3; i++) { - DWORD waitRes = WaitForSingleObject(event, 50); + DWORD waitRes = WaitForSingleObject(event, waitOnceTimeoutMillis); if (waitRes == WAIT_TIMEOUT && clipboard->context->IsStopped == FALSE) { continue; From 1dd599b011fcdd719adea77a049b6aa5e4dc795e Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 11:28:55 +0800 Subject: [PATCH 02/12] refact, win, clipboard, notify callback, tmp commit Signed-off-by: dignow --- libs/clipboard/src/cliprdr.h | 14 +++++++++++++- libs/clipboard/src/cliprdr.rs | 16 +++++++++++++++- libs/clipboard/src/context_send.rs | 8 +++++++- libs/clipboard/src/lib.rs | 10 ++++++++++ libs/clipboard/src/windows/wf_cliprdr.c | 13 ++++++++++++- 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/libs/clipboard/src/cliprdr.h b/libs/clipboard/src/cliprdr.h index 9d56049ee..2edb473fd 100644 --- a/libs/clipboard/src/cliprdr.h +++ b/libs/clipboard/src/cliprdr.h @@ -150,6 +150,15 @@ extern "C" typedef struct _cliprdr_client_context CliprdrClientContext; + struct _NOTIFICATION_MESSAGE + { + // 0 - info, 1 - warning, 2 - error + UINT32 type; + char *msg; + char *details; + }; + typedef struct _NOTIFICATION_MESSAGE NOTIFICATION_MESSAGE; + typedef UINT (*pcCliprdrServerCapabilities)(CliprdrClientContext *context, const CLIPRDR_CAPABILITIES *capabilities); typedef UINT (*pcCliprdrClientCapabilities)(CliprdrClientContext *context, @@ -158,6 +167,9 @@ extern "C" const CLIPRDR_MONITOR_READY *monitorReady); typedef UINT (*pcCliprdrTempDirectory)(CliprdrClientContext *context, const CLIPRDR_TEMP_DIRECTORY *tempDirectory); + + typedef UINT (*pcNotifyClipboardMsg)(const NOTIFICATION_MESSAGE *msg); + typedef UINT (*pcCliprdrClientFormatList)(CliprdrClientContext *context, const CLIPRDR_FORMAT_LIST *formatList); typedef UINT (*pcCliprdrServerFormatList)(CliprdrClientContext *context, @@ -204,6 +216,7 @@ extern "C" pcCliprdrClientCapabilities ClientCapabilities; pcCliprdrMonitorReady MonitorReady; pcCliprdrTempDirectory TempDirectory; + pcNotifyClipboardMsg NotifyClipboardMsg; pcCliprdrClientFormatList ClientFormatList; pcCliprdrServerFormatList ServerFormatList; pcCliprdrClientFormatListResponse ClientFormatListResponse; @@ -229,4 +242,3 @@ extern "C" #endif #endif // WF_CLIPRDR_H__ - diff --git a/libs/clipboard/src/cliprdr.rs b/libs/clipboard/src/cliprdr.rs index 6bbb27ca0..60475f72b 100644 --- a/libs/clipboard/src/cliprdr.rs +++ b/libs/clipboard/src/cliprdr.rs @@ -324,6 +324,14 @@ pub struct _CLIPRDR_FILE_CONTENTS_RESPONSE { } pub type CLIPRDR_FILE_CONTENTS_RESPONSE = _CLIPRDR_FILE_CONTENTS_RESPONSE; pub type CliprdrClientContext = _cliprdr_client_context; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _NOTIFICATION_MESSAGE { + pub r#type: UINT32, // 0 - info, 1 - warning, 2 - error + pub msg: *const BYTE, + pub details: *const BYTE, +} +pub type NOTIFICATION_MESSAGE = _NOTIFICATION_MESSAGE; pub type pcCliprdrServerCapabilities = ::std::option::Option< unsafe extern "C" fn( context: *mut CliprdrClientContext, @@ -348,6 +356,8 @@ pub type pcCliprdrTempDirectory = ::std::option::Option< tempDirectory: *const CLIPRDR_TEMP_DIRECTORY, ) -> UINT, >; +pub type pcNotifyClipboardMsg = + ::std::option::Option UINT>; pub type pcCliprdrClientFormatList = ::std::option::Option< unsafe extern "C" fn( context: *mut CliprdrClientContext, @@ -458,6 +468,7 @@ pub struct _cliprdr_client_context { pub ClientCapabilities: pcCliprdrClientCapabilities, pub MonitorReady: pcCliprdrMonitorReady, pub TempDirectory: pcCliprdrTempDirectory, + pub NotifyClipboardMsg: pcNotifyClipboardMsg, pub ClientFormatList: pcCliprdrClientFormatList, pub ServerFormatList: pcCliprdrServerFormatList, pub ClientFormatListResponse: pcCliprdrClientFormatListResponse, @@ -499,6 +510,8 @@ impl CliprdrClientContext { pub fn create( enable_files: bool, enable_others: bool, + response_wait_timeout_secs: u32, + notify_callback: pcNotifyClipboardMsg, client_format_list: pcCliprdrClientFormatList, client_format_list_response: pcCliprdrClientFormatListResponse, client_format_data_request: pcCliprdrClientFormatDataRequest, @@ -511,11 +524,12 @@ impl CliprdrClientContext { EnableFiles: if enable_files { TRUE } else { FALSE }, EnableOthers: if enable_others { TRUE } else { FALSE }, IsStopped: FALSE, - ResponseWaitTimeoutSecs: 60, + ResponseWaitTimeoutSecs: response_wait_timeout_secs, ServerCapabilities: None, ClientCapabilities: None, MonitorReady: None, TempDirectory: None, + NotifyClipboardMsg: notify_callback, ClientFormatList: client_format_list, ServerFormatList: None, ClientFormatListResponse: client_format_list_response, diff --git a/libs/clipboard/src/context_send.rs b/libs/clipboard/src/context_send.rs index 16363250e..76f8e4d7a 100644 --- a/libs/clipboard/src/context_send.rs +++ b/libs/clipboard/src/context_send.rs @@ -2,6 +2,8 @@ use crate::cliprdr::*; use hbb_common::log; use std::sync::Mutex; +const CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS: u32 = 30; + lazy_static::lazy_static! { static ref CONTEXT_SEND: ContextSend = ContextSend{addr: Mutex::new(0)}; } @@ -27,7 +29,11 @@ impl ContextSend { let mut lock = CONTEXT_SEND.addr.lock().unwrap(); if enabled { if *lock == 0 { - match crate::create_cliprdr_context(true, false) { + match crate::create_cliprdr_context( + true, + false, + CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS, + ) { Ok(context) => { log::info!("clipboard context for file transfer created."); *lock = Box::into_raw(context) as _; diff --git a/libs/clipboard/src/lib.rs b/libs/clipboard/src/lib.rs index c63817415..152dc0bcc 100644 --- a/libs/clipboard/src/lib.rs +++ b/libs/clipboard/src/lib.rs @@ -446,10 +446,13 @@ pub fn server_file_contents_response( pub fn create_cliprdr_context( enable_files: bool, enable_others: bool, + response_wait_timeout_secs: u32, ) -> ResultType> { Ok(CliprdrClientContext::create( enable_files, enable_others, + response_wait_timeout_secs, + Some(notify_callback), Some(client_format_list), Some(client_format_list_response), Some(client_format_data_request), @@ -459,6 +462,13 @@ pub fn create_cliprdr_context( )?) } +extern "C" fn notify_callback( + msg: *const NOTIFICATION_MESSAGE, +) -> UINT { + log::debug!("notify_callback called"); + 0 +} + extern "C" fn client_format_list( _context: *mut CliprdrClientContext, clip_format_list: *const CLIPRDR_FORMAT_LIST, diff --git a/libs/clipboard/src/windows/wf_cliprdr.c b/libs/clipboard/src/windows/wf_cliprdr.c index ea582d5b1..b9939121d 100644 --- a/libs/clipboard/src/windows/wf_cliprdr.c +++ b/libs/clipboard/src/windows/wf_cliprdr.c @@ -1455,7 +1455,8 @@ UINT wait_response_event(wfClipboard *clipboard, HANDLE event, void **data) clipboard->context->IsStopped = FALSE; DWORD waitOnceTimeoutMillis = 50; int waitCount = 1000 * clipboard->context->ResponseWaitTimeoutSecs / waitOnceTimeoutMillis; - for (int i = 0; i < waitCount * 3; i++) + int i = 0; + for (; i < waitCount; i++) { DWORD waitRes = WaitForSingleObject(event, waitOnceTimeoutMillis); if (waitRes == WAIT_TIMEOUT && clipboard->context->IsStopped == FALSE) @@ -1488,6 +1489,16 @@ UINT wait_response_event(wfClipboard *clipboard, HANDLE event, void **data) return rc; } + if (i == waitCount) + { + NOTIFICATION_MESSAGE msg; + msg.type = 2; + msg.msg = "timeout waiting for response"; + msg.details = NULL; + clipboard->context->NotifyClipboardMsg(&msg); + rc = ERROR_INTERNAL_ERROR; + } + if ((*data) != NULL) { if (!ResetEvent(event)) From fc8db69d9e56e3cea71488bbefb5c57f021b179b Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 13:47:55 +0800 Subject: [PATCH 03/12] refact, win, clipboard, notify callback, tmp commit Signed-off-by: dignow --- flutter/lib/common.dart | 12 +++++++- libs/clipboard/src/lib.rs | 37 +++++++++++++++++++++---- libs/clipboard/src/windows/wf_cliprdr.c | 2 +- src/flutter.rs | 33 ++++++++++++++++++++++ 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 67091db7a..3a4f1f638 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -998,6 +998,16 @@ Widget msgboxIcon(String type) { // title should be null Widget msgboxContent(String type, String title, String text) { + String translateText(String text) { + List words = text.split(' '); + if (words.isNotEmpty && words[0].endsWith('_tip')) { + words[0] = translate(words[0]); + return words.join(' '); + } else { + return translate(text); + } + } + return Row( children: [ msgboxIcon(type), @@ -1009,7 +1019,7 @@ Widget msgboxContent(String type, String title, String text) { translate(title), style: TextStyle(fontSize: 21), ).marginOnly(bottom: 10), - Text(translate(text), style: const TextStyle(fontSize: 15)), + Text(translateText(text), style: const TextStyle(fontSize: 15)), ], ), ), diff --git a/libs/clipboard/src/lib.rs b/libs/clipboard/src/lib.rs index 152dc0bcc..ee8f5644c 100644 --- a/libs/clipboard/src/lib.rs +++ b/libs/clipboard/src/lib.rs @@ -1,6 +1,6 @@ use cliprdr::*; use hbb_common::{ - allow_err, log, + allow_err, lazy_static, log, tokio::sync::{ mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}, Mutex as TokioMutex, @@ -19,6 +19,13 @@ pub mod context_send; 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>> = Default::default(); +} #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(tag = "t", content = "c")] @@ -462,11 +469,31 @@ pub fn create_cliprdr_context( )?) } -extern "C" fn notify_callback( - msg: *const NOTIFICATION_MESSAGE, -) -> UINT { +pub fn set_notify_callback(cb: FnNotifyCallback) { + NOTIFY_CALLBACK.lock().unwrap().replace(cb); +} + +extern "C" fn notify_callback(msg: *const NOTIFICATION_MESSAGE) -> UINT { log::debug!("notify_callback called"); - 0 + if let Some(cb) = NOTIFY_CALLBACK.lock().unwrap().as_ref() { + unsafe { + let msg = &*msg; + let details = if msg.details.is_null() { + Ok("") + } else { + 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), + _ => { + log::error!("notify_callback: failed to convert msg"); + ERR_CODE_INVALID_PARAMETER + } + } + } + } else { + ERR_CODE_SERVER_FUNCTION_NONE + } } extern "C" fn client_format_list( diff --git a/libs/clipboard/src/windows/wf_cliprdr.c b/libs/clipboard/src/windows/wf_cliprdr.c index b9939121d..407316d03 100644 --- a/libs/clipboard/src/windows/wf_cliprdr.c +++ b/libs/clipboard/src/windows/wf_cliprdr.c @@ -1493,7 +1493,7 @@ UINT wait_response_event(wfClipboard *clipboard, HANDLE event, void **data) { NOTIFICATION_MESSAGE msg; msg.type = 2; - msg.msg = "timeout waiting for response"; + msg.msg = "clipboard_wait_response_timeout_tip"; msg.details = NULL; clipboard->context->NotifyClipboardMsg(&msg); rc = ERROR_INTERNAL_ERROR; diff --git a/src/flutter.rs b/src/flutter.rs index 4008b2420..490a674fa 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -1089,6 +1089,39 @@ 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) { + 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([ + ("type", &msgtype as &str), + ("title", "clipboard"), + ("text", &text), + ("link", ""), + ("hasRetry", ""), + ])) { + push_global_event(channel, event); + } +} + +#[inline] +pub fn msgbox_clipboard_remote(r#type: u32, msg: &str, details: &str) { + msgbox_clipboard_(APP_TYPE_DESKTOP_REMOTE, r#type, msg, details); +} + +#[inline] +pub fn msgbox_clipboard_cm(r#type: u32, msg: &str, details: &str) { + msgbox_clipboard_(APP_TYPE_CM, r#type, msg, details); +} + #[no_mangle] unsafe extern "C" fn get_rgba() {} From 47fa90741f189b3cd04b37e7a7bf13efa60d0061 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 15:06:45 +0800 Subject: [PATCH 04/12] tmp commit Signed-off-by: dignow --- src/core_main.rs | 14 +++++++++++++- src/flutter.rs | 11 ++++++----- src/ui_cm_interface.rs | 8 ++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index f8741a72f..cd0067624 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -13,6 +13,8 @@ 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> { + use crate::flutter; + let mut args = Vec::new(); let mut flutter_args = Vec::new(); let mut i = 0; @@ -123,7 +125,17 @@ pub fn core_main() -> Option> { init_plugins(&args); if args.is_empty() { #[cfg(windows)] - clipboard::ContextSend::enable(true); + { + 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 { #[cfg(windows)] diff --git a/src/flutter.rs b/src/flutter.rs index 490a674fa..0a547acad 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -1089,7 +1089,7 @@ 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) { +fn msgbox_clipboard_(channel: &str, r#type: u32, msg: &str, details: &str) -> u32 { let msgtype = format!( "{}-nocancel-nook-hasclose", if r#type == 0 { @@ -1110,16 +1110,17 @@ fn msgbox_clipboard_(channel: &str, r#type: u32, msg: &str, details: &str) { ])) { push_global_event(channel, event); } + 0 } #[inline] -pub fn msgbox_clipboard_remote(r#type: u32, msg: &str, details: &str) { - msgbox_clipboard_(APP_TYPE_DESKTOP_REMOTE, r#type, msg, details); +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) { - msgbox_clipboard_(APP_TYPE_CM, r#type, msg, details); +pub fn msgbox_clipboard_cm(r#type: u32, msg: &str, details: &str) -> u32 { + msgbox_clipboard_(APP_TYPE_CM, r#type, msg, details) } #[no_mangle] diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index b61598251..2031d7f06 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -538,6 +538,14 @@ pub async fn start_ipc(cm: ConnectionManager) { #[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) => { From aaca56c1f8c0a02538d2d53f634d6804521ae49b Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 15:50:15 +0800 Subject: [PATCH 05/12] win, clipboard wait timeout, debug Signed-off-by: dignow --- libs/clipboard/src/windows/wf_cliprdr.c | 8 ++++++-- src/flutter.rs | 1 + src/lang/ca.rs | 1 + src/lang/cn.rs | 1 + src/lang/cs.rs | 1 + src/lang/da.rs | 1 + src/lang/de.rs | 1 + src/lang/el.rs | 1 + src/lang/en.rs | 1 + src/lang/eo.rs | 1 + src/lang/es.rs | 1 + src/lang/fa.rs | 1 + src/lang/fr.rs | 1 + src/lang/hu.rs | 1 + src/lang/id.rs | 1 + src/lang/it.rs | 1 + src/lang/ja.rs | 1 + src/lang/ko.rs | 1 + src/lang/kz.rs | 1 + src/lang/lt.rs | 1 + src/lang/nl.rs | 1 + src/lang/pl.rs | 1 + src/lang/pt_PT.rs | 1 + src/lang/ptbr.rs | 1 + src/lang/ro.rs | 1 + src/lang/ru.rs | 1 + src/lang/sk.rs | 1 + src/lang/sl.rs | 1 + src/lang/sq.rs | 1 + src/lang/sr.rs | 1 + src/lang/sv.rs | 1 + src/lang/template.rs | 1 + src/lang/th.rs | 1 + src/lang/tr.rs | 1 + src/lang/tw.rs | 1 + src/lang/ua.rs | 1 + src/lang/vn.rs | 1 + 37 files changed, 42 insertions(+), 2 deletions(-) diff --git a/libs/clipboard/src/windows/wf_cliprdr.c b/libs/clipboard/src/windows/wf_cliprdr.c index 407316d03..82b97216a 100644 --- a/libs/clipboard/src/windows/wf_cliprdr.c +++ b/libs/clipboard/src/windows/wf_cliprdr.c @@ -1497,9 +1497,13 @@ UINT wait_response_event(wfClipboard *clipboard, HANDLE event, void **data) msg.details = NULL; clipboard->context->NotifyClipboardMsg(&msg); rc = ERROR_INTERNAL_ERROR; - } - if ((*data) != NULL) + if (!ResetEvent(event)) + { + // NOTE: critical error here, crash may be better + } + } + else if ((*data) != NULL) { if (!ResetEvent(event)) { diff --git a/src/flutter.rs b/src/flutter.rs index 0a547acad..972374f23 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -1102,6 +1102,7 @@ fn msgbox_clipboard_(channel: &str, r#type: u32, msg: &str, details: &str) -> u3 ); 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), diff --git a/src/lang/ca.rs b/src/lang/ca.rs index 11f7a877a..b5163f68e 100644 --- a/src/lang/ca.rs +++ b/src/lang/ca.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/cn.rs b/src/lang/cn.rs index 2fe55a6bc..7fc27f687 100644 --- a/src/lang/cn.rs +++ b/src/lang/cn.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "折叠工具栏"), ("Accept and Elevate", "接受并提权"), ("accept_and_elevate_btn_tooltip", "接受连接并提升 UAC 权限"), + ("clipboard_wait_response_timeout_tip", "等待拷贝响应超时"), ].iter().cloned().collect(); } diff --git a/src/lang/cs.rs b/src/lang/cs.rs index cad262bea..5f279c7b9 100644 --- a/src/lang/cs.rs +++ b/src/lang/cs.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/da.rs b/src/lang/da.rs index 229cd5661..aaa5acf0e 100644 --- a/src/lang/da.rs +++ b/src/lang/da.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/de.rs b/src/lang/de.rs index fede1f3ae..1325aac4f 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "Symbolleiste einklappen"), ("Accept and Elevate", "Akzeptieren und Rechte erhöhen"), ("accept_and_elevate_btn_tooltip", "Akzeptieren Sie die Verbindung und erhöhen Sie die UAC-Berechtigungen."), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/el.rs b/src/lang/el.rs index 06d52f10a..6eacba007 100644 --- a/src/lang/el.rs +++ b/src/lang/el.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/en.rs b/src/lang/en.rs index c8e4f3f9f..9d759ada4 100644 --- a/src/lang/en.rs +++ b/src/lang/en.rs @@ -70,5 +70,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("resolution_fit_local_tip", "Fit local resolution"), ("resolution_custom_tip", "Custom resolution"), ("accept_and_elevate_btn_tooltip", "Accept the connection and elevate UAC permissions."), + ("clipboard_wait_response_timeout_tip", "Timed out waiting for copy response."), ].iter().cloned().collect(); } diff --git a/src/lang/eo.rs b/src/lang/eo.rs index 281601109..e232cb582 100644 --- a/src/lang/eo.rs +++ b/src/lang/eo.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/es.rs b/src/lang/es.rs index 57023178d..28d8832f0 100644 --- a/src/lang/es.rs +++ b/src/lang/es.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "Contraer barra de herramientas"), ("Accept and Elevate", "Aceptar y Elevar"), ("accept_and_elevate_btn_tooltip", "Aceptar la conexión y elevar permisos UAC."), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/fa.rs b/src/lang/fa.rs index 3da21726e..10b49ee98 100644 --- a/src/lang/fa.rs +++ b/src/lang/fa.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "جمع کردن نوار ابزار"), ("Accept and Elevate", "بپذیرید و افزایش دهید"), ("accept_and_elevate_btn_tooltip", "را افزایش دهید UAC اتصال را بپذیرید و مجوزهای."), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/fr.rs b/src/lang/fr.rs index 483ea8f44..e782e8dc0 100644 --- a/src/lang/fr.rs +++ b/src/lang/fr.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/hu.rs b/src/lang/hu.rs index 46bf48dd9..d9b95eeb0 100644 --- a/src/lang/hu.rs +++ b/src/lang/hu.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/id.rs b/src/lang/id.rs index c88faaba3..27cdcf1f1 100644 --- a/src/lang/id.rs +++ b/src/lang/id.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/it.rs b/src/lang/it.rs index 173bb843a..edc2eb9a8 100644 --- a/src/lang/it.rs +++ b/src/lang/it.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "Comprimi barra strumenti"), ("Accept and Elevate", "Accetta ed eleva"), ("accept_and_elevate_btn_tooltip", "Accetta la connessione ed eleva le autorizzazioni UAC."), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ja.rs b/src/lang/ja.rs index b02cca143..5def2cfca 100644 --- a/src/lang/ja.rs +++ b/src/lang/ja.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ko.rs b/src/lang/ko.rs index 4a052e844..90040b964 100644 --- a/src/lang/ko.rs +++ b/src/lang/ko.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/kz.rs b/src/lang/kz.rs index efdb9718b..6bb1c7a95 100644 --- a/src/lang/kz.rs +++ b/src/lang/kz.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/lt.rs b/src/lang/lt.rs index 247a81511..d2402c7f2 100644 --- a/src/lang/lt.rs +++ b/src/lang/lt.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/nl.rs b/src/lang/nl.rs index 14763515b..2e0de4906 100644 --- a/src/lang/nl.rs +++ b/src/lang/nl.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "Werkbalk samenvouwen"), ("Accept and Elevate", "Accepteren en Verheffen"), ("accept_and_elevate_btn_tooltip", "Accepteer de verbinding en verhoog de UAC-machtigingen."), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pl.rs b/src/lang/pl.rs index 09d62b384..dfa6834ca 100644 --- a/src/lang/pl.rs +++ b/src/lang/pl.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "Zwiń pasek narzędzi"), ("Accept and Elevate", "Akceptuj i Podnieś uprawnienia"), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pt_PT.rs b/src/lang/pt_PT.rs index aa91a974f..743154d5f 100644 --- a/src/lang/pt_PT.rs +++ b/src/lang/pt_PT.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ptbr.rs b/src/lang/ptbr.rs index 594a57cc1..3bcc10e6c 100644 --- a/src/lang/ptbr.rs +++ b/src/lang/ptbr.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ro.rs b/src/lang/ro.rs index 18e21e29a..b75d5950d 100644 --- a/src/lang/ro.rs +++ b/src/lang/ro.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ru.rs b/src/lang/ru.rs index 2e0128cdd..d7e707988 100644 --- a/src/lang/ru.rs +++ b/src/lang/ru.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "Свернуть панель инструментов"), ("Accept and Elevate", "Принять и повысить"), ("accept_and_elevate_btn_tooltip", "Разрешить подключение и повысить права UAC."), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sk.rs b/src/lang/sk.rs index ca308a7be..c99330096 100644 --- a/src/lang/sk.rs +++ b/src/lang/sk.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sl.rs b/src/lang/sl.rs index 691c77968..99e3f2805 100755 --- a/src/lang/sl.rs +++ b/src/lang/sl.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sq.rs b/src/lang/sq.rs index 5b2e34e27..04735b4b8 100644 --- a/src/lang/sq.rs +++ b/src/lang/sq.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sr.rs b/src/lang/sr.rs index e9c8178e9..9a9e251de 100644 --- a/src/lang/sr.rs +++ b/src/lang/sr.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sv.rs b/src/lang/sv.rs index 0e17e1a26..73eb138bd 100644 --- a/src/lang/sv.rs +++ b/src/lang/sv.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/template.rs b/src/lang/template.rs index 1cd755c53..e5fa47fd2 100644 --- a/src/lang/template.rs +++ b/src/lang/template.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/th.rs b/src/lang/th.rs index 3f1127932..78aa94c6f 100644 --- a/src/lang/th.rs +++ b/src/lang/th.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tr.rs b/src/lang/tr.rs index 64c97fcf3..bc9cd694f 100644 --- a/src/lang/tr.rs +++ b/src/lang/tr.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tw.rs b/src/lang/tw.rs index 123a259e7..5f5136134 100644 --- a/src/lang/tw.rs +++ b/src/lang/tw.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ua.rs b/src/lang/ua.rs index 4b3d87019..135b3b357 100644 --- a/src/lang/ua.rs +++ b/src/lang/ua.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", ""), ("Accept and Elevate", ""), ("accept_and_elevate_btn_tooltip", ""), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } diff --git a/src/lang/vn.rs b/src/lang/vn.rs index 04d9abcc2..05689843b 100644 --- a/src/lang/vn.rs +++ b/src/lang/vn.rs @@ -511,5 +511,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Collapse toolbar", "Thu nhỏ thanh công cụ"), ("Accept and Elevate", "Chấp nhận và Cấp Quyền"), ("accept_and_elevate_btn_tooltip", "Chấp nhận kết nối và cấp các quyền UAC."), + ("clipboard_wait_response_timeout_tip", ""), ].iter().cloned().collect(); } From 1f71dc979cbb728709ac010b093d5c54d116b2fa Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 18:12:34 +0800 Subject: [PATCH 06/12] tmp commit Signed-off-by: dignow --- libs/clipboard/src/cliprdr.h | 2 +- libs/clipboard/src/cliprdr.rs | 2 +- libs/clipboard/src/context_send.rs | 2 +- libs/clipboard/src/lib.rs | 93 ++++++++++++++----------- libs/clipboard/src/windows/wf_cliprdr.c | 8 +-- src/client/io_loop.rs | 25 ++++--- src/clipboard_file.rs | 14 ++++ src/core_main.rs | 10 --- src/flutter.rs | 35 ---------- src/ui_cm_interface.rs | 10 +-- 10 files changed, 89 insertions(+), 112 deletions(-) diff --git a/libs/clipboard/src/cliprdr.h b/libs/clipboard/src/cliprdr.h index 2edb473fd..8b9cecef0 100644 --- a/libs/clipboard/src/cliprdr.h +++ b/libs/clipboard/src/cliprdr.h @@ -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); diff --git a/libs/clipboard/src/cliprdr.rs b/libs/clipboard/src/cliprdr.rs index 60475f72b..c787d8ef6 100644 --- a/libs/clipboard/src/cliprdr.rs +++ b/libs/clipboard/src/cliprdr.rs @@ -357,7 +357,7 @@ pub type pcCliprdrTempDirectory = ::std::option::Option< ) -> UINT, >; pub type pcNotifyClipboardMsg = - ::std::option::Option UINT>; + ::std::option::Option UINT>; pub type pcCliprdrClientFormatList = ::std::option::Option< unsafe extern "C" fn( context: *mut CliprdrClientContext, diff --git a/libs/clipboard/src/context_send.rs b/libs/clipboard/src/context_send.rs index 76f8e4d7a..95350effc 100644 --- a/libs/clipboard/src/context_send.rs +++ b/libs/clipboard/src/context_send.rs @@ -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)}; diff --git a/libs/clipboard/src/lib.rs b/libs/clipboard/src/lib.rs index ee8f5644c..3a9c6308c 100644 --- a/libs/clipboard/src/lib.rs +++ b/libs/clipboard/src/lib.rs @@ -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>> = 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,9 +247,9 @@ pub fn server_clip_file( requested_data, ); log::debug!("server_file_contents_response called, return {}", ret); - ret } } + ret } pub fn server_monitor_ready(context: &mut Box, conn_id: i32) -> u32 { @@ -469,31 +466,45 @@ 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 msg = &*msg; - let details = if msg.details.is_null() { - Ok("") - } else { - 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), - _ => { - log::error!("notify_callback: failed to convert msg"); - ERR_CODE_INVALID_PARAMETER + let data = unsafe { + let msg = &*msg; + let details = if msg.details.is_null() { + Ok("") + } else { + CStr::from_ptr(msg.details as _).to_str() + }; + match (CStr::from_ptr(msg.msg as _).to_str(), details) { + (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"); + 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( diff --git a/libs/clipboard/src/windows/wf_cliprdr.c b/libs/clipboard/src/windows/wf_cliprdr.c index 82b97216a..801fa71f3 100644 --- a/libs/clipboard/src/windows/wf_cliprdr.c +++ b/libs/clipboard/src/windows/wf_cliprdr.c @@ -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( diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index d75b53888..ff1387dd0 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -206,16 +206,21 @@ impl Remote { _msg = rx_clip_client.recv() => { #[cfg(windows)] match _msg { - Some(clip) => { - 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; - let stop = is_stopping_allowed && !(server_file_transfer_enabled && file_transfer_enabled); - log::debug!("Process clipboard message from system, stop: {}, is_stopping_allowed: {}, server_file_transfer_enabled: {}, file_transfer_enabled: {}", stop, is_stopping_allowed, server_file_transfer_enabled, file_transfer_enabled); - if stop { - ContextSend::set_is_stopped(); - } else { - allow_err!(peer.send(&crate::clipboard_file::clip_2_msg(clip)).await); + 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; + let stop = is_stopping_allowed && !(server_file_transfer_enabled && file_transfer_enabled); + log::debug!("Process clipboard message from system, stop: {}, is_stopping_allowed: {}, server_file_transfer_enabled: {}, file_transfer_enabled: {}", stop, is_stopping_allowed, server_file_transfer_enabled, file_transfer_enabled); + if stop { + ContextSend::set_is_stopped(); + } else { + allow_err!(peer.send(&crate::clipboard_file::clip_2_msg(clip)).await); + } } } None => { diff --git a/src/clipboard_file.rs b/src/clipboard_file.rs index f0fe41b8d..a4bfc1aef 100644 --- a/src/clipboard_file.rs +++ b/src/clipboard_file.rs @@ -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 { diff --git a/src/core_main.rs b/src/core_main.rs index cd0067624..5a8638419 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -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> { - 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> { #[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 { diff --git a/src/flutter.rs b/src/flutter.rs index 972374f23..4008b2420 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -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() {} diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 2031d7f06..e5a5c8e3b 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -423,7 +423,7 @@ impl IpcTaskRunner { Data::ClipboardFileEnabled(_enabled) => { #[cfg(windows)] { - self.file_transfer_enabled_peer =_enabled; + self.file_transfer_enabled_peer = _enabled; } } Data::Theme(dark) => { @@ -538,14 +538,6 @@ pub async fn start_ipc(cm: ConnectionManager) { #[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) => { From 88997866282c9875355b7d5798ad447eaa94ea5d Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 20:41:33 +0800 Subject: [PATCH 07/12] debug ok Signed-off-by: dignow --- libs/clipboard/src/context_send.rs | 2 +- libs/clipboard/src/lib.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/clipboard/src/context_send.rs b/libs/clipboard/src/context_send.rs index 95350effc..76f8e4d7a 100644 --- a/libs/clipboard/src/context_send.rs +++ b/libs/clipboard/src/context_send.rs @@ -2,7 +2,7 @@ use crate::cliprdr::*; use hbb_common::log; use std::sync::Mutex; -const CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS: u32 = 0; +const CLIPBOARD_RESPONSE_WAIT_TIMEOUT_SECS: u32 = 30; lazy_static::lazy_static! { static ref CONTEXT_SEND: ContextSend = ContextSend{addr: Mutex::new(0)}; diff --git a/libs/clipboard/src/lib.rs b/libs/clipboard/src/lib.rs index 3a9c6308c..63f8df165 100644 --- a/libs/clipboard/src/lib.rs +++ b/libs/clipboard/src/lib.rs @@ -488,7 +488,11 @@ extern "C" fn notify_callback(conn_id: UINT32, msg: *const NOTIFICATION_MESSAGE) } ); let title = "Clipboard"; - let text = format!("{}: {}", m, d); + let text = if d.is_empty() { + m.to_string() + } else { + format!("{} {}", m, d) + }; ClipboardFile::NotifyCallback { r#type: msgtype, title: title.to_string(), From 4c1eb75129065a1da8da59232e8dcc5441283b81 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 20:57:42 +0800 Subject: [PATCH 08/12] trival change Signed-off-by: dignow --- src/core_main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index 5a8638419..f8741a72f 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -123,9 +123,7 @@ pub fn core_main() -> Option> { init_plugins(&args); if args.is_empty() { #[cfg(windows)] - { - clipboard::ContextSend::enable(true); - } + clipboard::ContextSend::enable(true); std::thread::spawn(move || crate::start_server(false)); } else { #[cfg(windows)] From 2c0918fc06a30b13b9b982ec5159624a1bce16e6 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 22:25:01 +0800 Subject: [PATCH 09/12] debug done Signed-off-by: dignow --- flutter/lib/common.dart | 20 +++++++++++++++----- libs/clipboard/src/lib.rs | 2 +- src/server/video_service.rs | 2 +- src/ui/msgbox.tis | 9 +++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 3a4f1f638..d294cb573 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -999,13 +999,23 @@ Widget msgboxIcon(String type) { // title should be null Widget msgboxContent(String type, String title, String text) { String translateText(String text) { - List words = text.split(' '); - if (words.isNotEmpty && words[0].endsWith('_tip')) { - words[0] = translate(words[0]); - return words.join(' '); + if (text.indexOf('Failed') == 0 && text.contains(': ')) { + List words = text.split(': '); + for (var i = 0; i < words.length; ++i) { + words[i] = translate(words[i]); + } + text = words.join(': '); } else { - return translate(text); + List words = text.split(' '); + if (words.length > 1 && words[0].endsWith('_tip')) { + words[0] = translate(words[0]); + final rest = text.substring(words[0].length + 1); + text = '${words[0]} ${translate(rest)}'; + } else { + text = translate(text); + } } + return text; } return Row( diff --git a/libs/clipboard/src/lib.rs b/libs/clipboard/src/lib.rs index 63f8df165..84179621d 100644 --- a/libs/clipboard/src/lib.rs +++ b/libs/clipboard/src/lib.rs @@ -478,7 +478,7 @@ extern "C" fn notify_callback(conn_id: UINT32, msg: *const NOTIFICATION_MESSAGE) match (CStr::from_ptr(msg.msg as _).to_str(), details) { (Ok(m), Ok(d)) => { let msgtype = format!( - "{}-nocancel-nook-hasclose", + "custom-{}-nocancel-nook-hasclose", if msg.r#type == 0 { "info" } else if msg.r#type == 1 { diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 90c262cc9..ada41e266 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -987,7 +987,7 @@ fn try_get_displays() -> ResultType> { } #[inline] -#[cfg(windows)] +#[cfg(all(windows, feature = "virtual_display_driver"))] fn no_displays(displays: &Vec) -> bool { let display_len = displays.len(); if display_len == 0 { diff --git a/src/ui/msgbox.tis b/src/ui/msgbox.tis index 8d54bf22c..d54b22c8e 100644 --- a/src/ui/msgbox.tis +++ b/src/ui/msgbox.tis @@ -5,6 +5,15 @@ function translate_text(text) { fds[i] = translate(fds[i]); } text = fds.join(': '); + } else { + var fds = text.split(' '); + if (fds.length > 1 && fds[0].slice(-4) === '_tip') { + fds[0] = translate(fds[0]); + var rest = text.substring(fds[0].length + 1); + text = fds[0] + ' ' + translate(rest); + } else { + text = translate(text); + } } return text; } From 83b8899414a9b5119c6857c2018af9fdca4e778d Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 22:35:52 +0800 Subject: [PATCH 10/12] remove translate _tip in a sentence with other words Signed-off-by: dignow --- flutter/lib/common.dart | 9 +-------- src/ui/msgbox.tis | 9 --------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index d294cb573..4beda68ef 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1006,14 +1006,7 @@ Widget msgboxContent(String type, String title, String text) { } text = words.join(': '); } else { - List words = text.split(' '); - if (words.length > 1 && words[0].endsWith('_tip')) { - words[0] = translate(words[0]); - final rest = text.substring(words[0].length + 1); - text = '${words[0]} ${translate(rest)}'; - } else { - text = translate(text); - } + text = translate(text); } return text; } diff --git a/src/ui/msgbox.tis b/src/ui/msgbox.tis index d54b22c8e..8d54bf22c 100644 --- a/src/ui/msgbox.tis +++ b/src/ui/msgbox.tis @@ -5,15 +5,6 @@ function translate_text(text) { fds[i] = translate(fds[i]); } text = fds.join(': '); - } else { - var fds = text.split(' '); - if (fds.length > 1 && fds[0].slice(-4) === '_tip') { - fds[0] = translate(fds[0]); - var rest = text.substring(fds[0].length + 1); - text = fds[0] + ' ' + translate(rest); - } else { - text = translate(text); - } } return text; } From b7bc8f23da3ef2d8c211b4c413a45f0e8129f220 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 22:44:15 +0800 Subject: [PATCH 11/12] Revert "remove translate _tip in a sentence with other words" This reverts commit 83b8899414a9b5119c6857c2018af9fdca4e778d. --- flutter/lib/common.dart | 9 ++++++++- src/ui/msgbox.tis | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 4beda68ef..d294cb573 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1006,7 +1006,14 @@ Widget msgboxContent(String type, String title, String text) { } text = words.join(': '); } else { - text = translate(text); + List words = text.split(' '); + if (words.length > 1 && words[0].endsWith('_tip')) { + words[0] = translate(words[0]); + final rest = text.substring(words[0].length + 1); + text = '${words[0]} ${translate(rest)}'; + } else { + text = translate(text); + } } return text; } diff --git a/src/ui/msgbox.tis b/src/ui/msgbox.tis index 8d54bf22c..d54b22c8e 100644 --- a/src/ui/msgbox.tis +++ b/src/ui/msgbox.tis @@ -5,6 +5,15 @@ function translate_text(text) { fds[i] = translate(fds[i]); } text = fds.join(': '); + } else { + var fds = text.split(' '); + if (fds.length > 1 && fds[0].slice(-4) === '_tip') { + fds[0] = translate(fds[0]); + var rest = text.substring(fds[0].length + 1); + text = fds[0] + ' ' + translate(rest); + } else { + text = translate(text); + } } return text; } From 44f3eeabd11ea040a163ba8329564fae04c82593 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 22:48:51 +0800 Subject: [PATCH 12/12] trivial change Signed-off-by: dignow --- flutter/lib/common.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index d294cb573..7827ee13c 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -999,7 +999,7 @@ Widget msgboxIcon(String type) { // title should be null Widget msgboxContent(String type, String title, String text) { String translateText(String text) { - if (text.indexOf('Failed') == 0 && text.contains(': ')) { + if (text.indexOf('Failed') == 0 && text.indexOf(': ') > 0) { List words = text.split(': '); for (var i = 0; i < words.length; ++i) { words[i] = translate(words[i]);