Skip to content

Commit 1dc0011

Browse files
committed
feat: 菜单添加应用重启按钮
1 parent 8360c53 commit 1dc0011

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

template-creator/src-tauri/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ fn main() {
1818
.menu(menu)
1919
.on_menu_event(move |event| match event.menu_item_id() {
2020
"app_quit" => {
21-
std::process::exit(0);
21+
event.window().app_handle().exit(0);
22+
}
23+
"app_restart" => {
24+
event.window().app_handle().restart();
2225
}
2326
"window_close" => {
2427
event.window().close().unwrap();

template-creator/src-tauri/src/menus.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn create_menus() -> Menu {
2323
let menu_item_quit = MTCMenu::new("app_quit", "退出")
2424
.build()
2525
.accelerator("CmdOrCtrl+Q");
26+
let menu_item_restart = MTCMenu::new("app_restart", "重启").build();
2627
let menu_item_project_new = MTCMenu::new("project_new", "新建项目")
2728
.build()
2829
.accelerator("CmdOrCtrl+N");
@@ -48,6 +49,7 @@ pub fn create_menus() -> Menu {
4849
.add_native_item(MenuItem::Separator)
4950
.add_item(menu_item_project_export)
5051
.add_native_item(MenuItem::Separator)
52+
.add_item(menu_item_restart)
5153
.add_item(menu_item_quit),
5254
);
5355
// 子菜单 - 帮助

0 commit comments

Comments
 (0)