Skip to content

Commit

Permalink
fix: 优化icon的交互体验
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyios committed Nov 20, 2023
1 parent a303ac2 commit 63618ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
27 changes: 9 additions & 18 deletions src-tauri/src/app/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,18 @@ pub fn menu_event_handle(event: WindowMenuEvent) {
}

#[cfg(any(target_os = "linux", target_os = "windows"))]
pub fn get_system_tray(show_menu: bool) -> SystemTray {
let hide_app = CustomMenuItem::new("hide_app".to_string(), "Hide App");
let show_app = CustomMenuItem::new("show_app".to_string(), "Show App");
pub fn get_system_tray() -> SystemTray {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let about = CustomMenuItem::new("about".to_string(), "About");
let tray_menu = SystemTrayMenu::new().add_item(hide_app).add_item(show_app);
if show_menu {
let hide_menu = CustomMenuItem::new("hide_menu".to_string(), "Hide Menu");
let show_menu = CustomMenuItem::new("show_menu".to_string(), "Show Menu");
let tray_menu = tray_menu
.add_item(hide_menu)
.add_item(show_menu)
.add_item(quit)
.add_item(about);
SystemTray::new().with_menu(tray_menu)
} else {
let tray_menu = tray_menu.add_item(quit).add_item(about);
SystemTray::new().with_menu(tray_menu)
}
let tray_menu = SystemTrayMenu::new().add_item(quit);
return SystemTray::new().with_menu(tray_menu);
}

#[cfg(any(target_os = "linux", target_os = "windows"))]
pub fn system_tray_handle(app: &tauri::AppHandle, event: SystemTrayEvent) {
if let SystemTrayEvent::LeftClick{..} = event {
app.get_window("pake").unwrap().set_focus().unwrap();
}

if let SystemTrayEvent::MenuItemClick { tray_id: _, id, .. } = event {
match id.as_str() {
"hide_app" => {
Expand Down Expand Up @@ -112,4 +101,6 @@ pub fn system_tray_handle(app: &tauri::AppHandle, event: SystemTrayEvent) {
_ => {}
}
};


}
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn run_app() {
use menu::{get_system_tray, system_tray_handle};

let show_system_tray = pake_config.show_system_tray();
let system_tray = get_system_tray(show_menu);
let system_tray = get_system_tray();

if show_system_tray {
tauri_app = tauri_app
Expand Down

0 comments on commit 63618ad

Please sign in to comment.