-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.rs
57 lines (49 loc) · 1.96 KB
/
menu.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use tauri::{
menu::{
CheckMenuItemBuilder, MenuBuilder, MenuItemBuilder, PredefinedMenuItem,
SubmenuBuilder,
},
AppHandle,
};
pub fn setup_menu(
handle: &AppHandle,
label: &str,
) -> Result<(), Box<dyn std::error::Error>> {
let pkg_info = handle.package_info();
let app_name = &pkg_info.name.clone();
let app_menu = SubmenuBuilder::new(handle, app_name).quit().build()?;
let native_menu = SubmenuBuilder::new(handle, "NativeMenu")
.items(&[
&PredefinedMenuItem::about(handle, Some("关于"), None),
&PredefinedMenuItem::services(handle, Some("服务")),
&PredefinedMenuItem::hide(handle, Some("隐藏")),
&PredefinedMenuItem::hide_others(handle, Some("隐藏其他")),
&PredefinedMenuItem::show_all(handle, Some("显示全部")),
&PredefinedMenuItem::quit(handle, Some("退出")),
&PredefinedMenuItem::close_window(handle, Some("关闭窗口")),
&PredefinedMenuItem::undo(handle, Some("撤销")),
&PredefinedMenuItem::redo(handle, Some("重做")),
&PredefinedMenuItem::cut(handle, Some("剪切")),
&PredefinedMenuItem::copy(handle, Some("拷贝")),
&PredefinedMenuItem::paste(handle, Some("粘贴")),
&PredefinedMenuItem::select_all(handle, Some("全选")),
&PredefinedMenuItem::fullscreen(handle, Some("切换全屏")),
&PredefinedMenuItem::minimize(handle, Some("最小化")),
&PredefinedMenuItem::maximize(handle, Some("最大化")),
])
.build()?;
// only for "win_1"
let custom_menu = SubmenuBuilder::new(handle, "Test")
.item(&MenuItemBuilder::with_id("toggle", "Toggle").build(handle))
.item(&CheckMenuItemBuilder::new("Mark").build(handle))
.build()?;
let mut menus = MenuBuilder::new(handle).item(&app_menu).item(&native_menu);
if label == "win1" {
menus = menus.item(&custom_menu);
}
handle.set_menu(menus.build()?)?;
handle.on_menu_event(move |handle, event| {
println!("event id: {:?}", event.id);
});
Ok(())
}