feat: native menu supports

This commit is contained in:
GyDi 2022-02-27 01:29:57 +08:00
parent b6aa50d3dc
commit d05d8d6a9e
No known key found for this signature in database
GPG Key ID: 58B15242BA8277A6

View File

@ -10,7 +10,8 @@ mod utils;
use crate::utils::{resolve, server};
use tauri::{
api, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
api, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray, SystemTrayEvent,
SystemTrayMenu, SystemTrayMenuItem,
};
fn main() -> std::io::Result<()> {
@ -19,7 +20,18 @@ fn main() -> std::io::Result<()> {
return Ok(());
}
let menu = SystemTrayMenu::new()
let submenu_file = Submenu::new(
"File",
Menu::new()
.add_native_item(MenuItem::Undo)
.add_native_item(MenuItem::Redo)
.add_native_item(MenuItem::Copy)
.add_native_item(MenuItem::Paste)
.add_native_item(MenuItem::Cut)
.add_native_item(MenuItem::SelectAll),
);
let tray_menu = SystemTrayMenu::new()
.add_item(CustomMenuItem::new("open_window", "Show"))
.add_item(CustomMenuItem::new("restart_clash", "Restart Clash"))
.add_native_item(SystemTrayMenuItem::Separator)
@ -30,7 +42,8 @@ fn main() -> std::io::Result<()> {
.manage(states::ClashState::default())
.manage(states::ProfilesState::default())
.setup(|app| Ok(resolve::resolve_setup(app)))
.system_tray(SystemTray::new().with_menu(menu))
.menu(Menu::new().add_submenu(submenu_file))
.system_tray(SystemTray::new().with_menu(tray_menu))
.on_system_tray_event(move |app_handle, event| match event {
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"open_window" => {