refact, win, clipboard, notify callback, tmp commit

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-06-29 13:47:55 +08:00
parent 1dd599b011
commit fc8db69d9e
4 changed files with 77 additions and 7 deletions

View File

@ -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<String> 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)),
],
),
),

View File

@ -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<Mutex<Option<FnNotifyCallback>>> = 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(

View File

@ -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;

View File

@ -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() {}