[feat] start hidden + hidden on close + basic tray function

This commit is contained in:
Purp1e
2025-03-26 03:00:18 +08:00
parent e0a84a0570
commit ee03bf0160
20 changed files with 266 additions and 40 deletions

View File

@@ -5,8 +5,12 @@ use tauri::{
};
pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&quit_i])?;
// 托盘菜单项目
let show_i = MenuItem::with_id(app, "show", "显示主界面", true, None::<&str>)?;
let quit_i = MenuItem::with_id(app, "quit", "退出", true, None::<&str>)?;
// 创建托盘菜单
let menu = Menu::with_items(app, &[&show_i, &quit_i])?;
let _ = TrayIconBuilder::with_id("tray")
.icon(app.default_window_icon().unwrap().clone())
@@ -16,6 +20,12 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
"quit" => {
app.exit(0);
}
"show" => {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
// Add more events here
_ => {}
})