From 575311b40d3903b4d438737b7ad64f741a29adf1 Mon Sep 17 00:00:00 2001 From: Yezzi Hsueh Date: Fri, 1 Nov 2024 19:09:25 +0800 Subject: [PATCH] fix: set focus --- src-tauri/src/lib.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f56cfe9..82de9ea 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -25,9 +25,16 @@ pub fn run() { button_state: MouseButtonState::Up, .. } => { - icon.app_handle() - .get_window("main").unwrap() - .show().unwrap(); + let window = icon.app_handle().get_window("main").unwrap(); + if !window.is_visible().unwrap() { + window.show().unwrap(); + } + if window.is_minimized().unwrap() { + window.unminimize().unwrap(); + } + if !window.is_focused().unwrap() { + window.set_focus().unwrap(); + } println!("Tray icon clicked"); } _ => {} @@ -36,13 +43,13 @@ pub fn run() { .menu_on_left_click(false) .on_menu_event(|app, event| match event.id.as_ref() { "quit" => { - println!("quit menu item was clicked"); - app.exit(0); + println!("quit menu item was clicked"); + app.exit(0); } _ => { - println!("menu item {:?} not handled", event.id); + println!("menu item {:?} not handled", event.id); } - }) + }) .build(app)?; Ok(()) })