Skip to content

Commit

Permalink
feat: add display tray menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
pkptzx authored and orangelckc committed Mar 31, 2023
1 parent d34dbc7 commit 330898e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 7 additions & 8 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub async fn show_in_folder(path: String) {

#[cfg(target_os = "linux")]
{
use std::fs;
use std::fs::metadata;
use std::path::PathBuf;
if path.contains(",") {
Expand Down Expand Up @@ -52,10 +51,10 @@ pub async fn show_in_folder(path: String) {
// 页面加载
#[tauri::command]
pub fn close_splashscreen(window: tauri::Window) {
// 关闭启动视图
if let Some(splashscreen) = window.get_window("splashscreen") {
splashscreen.close().unwrap();
}
// 展示主视图
window.get_window("main").unwrap().show().unwrap();
}
// 关闭启动视图
if let Some(splashscreen) = window.get_window("splashscreen") {
splashscreen.close().unwrap();
}
// 展示主视图
window.get_window("main").unwrap().show().unwrap();
}
8 changes: 7 additions & 1 deletion src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use tauri::{AppHandle, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, Sys

// 加载菜单
pub fn main_menu() -> SystemTray {
let tray_menu = SystemTrayMenu::new().add_item(CustomMenuItem::new("quit".to_string(), "退出"));
let tray_menu = SystemTrayMenu::new()
.add_item(CustomMenuItem::new("show".to_string(), "显示"))
.add_item(CustomMenuItem::new("quit".to_string(), "退出"));

SystemTray::new().with_menu(tray_menu)
}
Expand All @@ -20,6 +22,10 @@ pub fn handler(app: &AppHandle, event: SystemTrayEvent) {
println!("右键点击图标");
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"show" => app.windows().values().for_each(|window| {
window.show().unwrap();
window.set_focus().unwrap();
}),
"quit" => std::process::exit(0),
_ => {}
},
Expand Down

0 comments on commit 330898e

Please sign in to comment.