From 47fa90741f189b3cd04b37e7a7bf13efa60d0061 Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 29 Jun 2023 15:06:45 +0800 Subject: [PATCH] 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) => {