@@ -137,7 +137,8 @@ pub fn run() {
137137 local:: application:: get_default_search_paths,
138138 local:: application:: list_app_with_metadata_in,
139139 util:: open,
140- server:: system_settings:: get_system_settings
140+ server:: system_settings:: get_system_settings,
141+ simulate_mouse_click
141142 ] )
142143 . setup ( |app| {
143144 let registry = SearchSourceRegistry :: default ( ) ;
@@ -251,13 +252,13 @@ async fn init_app_search_source<R: Runtime>(app_handle: &AppHandle<R>) -> Result
251252#[ tauri:: command]
252253async fn show_coco < R : Runtime > ( app_handle : AppHandle < R > ) {
253254 if let Some ( window) = app_handle. get_window ( MAIN_WINDOW_LABEL ) {
254- let _ = app_handle. emit ( "show-coco" , ( ) ) ;
255-
256255 move_window_to_active_monitor ( & window) ;
257256
258257 let _ = window. show ( ) ;
259258 let _ = window. unminimize ( ) ;
260259 let _ = window. set_focus ( ) ;
260+
261+ let _ = app_handle. emit ( "show-coco" , ( ) ) ;
261262 }
262263}
263264
@@ -412,3 +413,49 @@ async fn get_app_search_source<R: Runtime>(app_handle: AppHandle<R>) -> Result<(
412413async fn show_settings ( app_handle : AppHandle ) {
413414 open_settings ( & app_handle) ;
414415}
416+
417+ #[ tauri:: command]
418+ async fn simulate_mouse_click < R : Runtime > ( window : WebviewWindow < R > , is_chat_mode : bool ) {
419+ #[ cfg( target_os = "windows" ) ]
420+ {
421+ use enigo:: { Button , Coordinate , Direction , Enigo , Mouse , Settings } ;
422+ use std:: { thread, time:: Duration } ;
423+
424+ if let Ok ( mut enigo) = Enigo :: new ( & Settings :: default ( ) ) {
425+ // Save the current mouse position
426+ if let Ok ( ( original_x, original_y) ) = enigo. location ( ) {
427+ // Retrieve the window's outer position (top-left corner)
428+ if let Ok ( position) = window. outer_position ( ) {
429+ // Retrieve the window's inner size (client area)
430+ if let Ok ( size) = window. inner_size ( ) {
431+ // Calculate the center position of the title bar
432+ let x = position. x + ( size. width as i32 / 2 ) ;
433+ let y = if is_chat_mode {
434+ position. y + size. height as i32 - 50
435+ } else {
436+ position. y + 30
437+ } ;
438+
439+ // Move the mouse cursor to the calculated position
440+ if enigo. move_mouse ( x, y, Coordinate :: Abs ) . is_ok ( ) {
441+ // // Simulate a left mouse click
442+ let _ = enigo. button ( Button :: Left , Direction :: Click ) ;
443+ // let _ = enigo.button(Button::Left, Direction::Release);
444+
445+ thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
446+
447+ // Move the mouse cursor back to the original position
448+ let _ = enigo. move_mouse ( original_x, original_y, Coordinate :: Abs ) ;
449+ }
450+ }
451+ }
452+ }
453+ }
454+ }
455+
456+ #[ cfg( not( target_os = "windows" ) ) ]
457+ {
458+ let _ = window;
459+ let _ = is_chat_mode;
460+ }
461+ }
0 commit comments