I created a Tauri App using yarn create tauri-app, and then changed the main.rs file to:
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{CustomMenuItem, Menu, MenuEntry, MenuItem, Submenu, WindowMenuEvent};
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
fn app_menu() -> Menu {
Menu::with_items([MenuEntry::Submenu(Submenu::new(
"File",
Menu::with_items([
CustomMenuItem::new("New", "New")
.accelerator("CmdOrCtrl+N")
.into(),
CustomMenuItem::new("Open", "Open")
.accelerator("CmdOrCtrl+O")
.into(),
MenuItem::Separator.into(),
CustomMenuItem::new("Save", "Save")
.accelerator("CmdOrCtrl+S")
.into(),
CustomMenuItem::new("SaveAs", "SaveAs")
.accelerator("CmdOrCtrl+Shift+S")
.into(),
MenuItem::Separator.into(),
CustomMenuItem::new("Close", "Close")
.accelerator("CmdOrCtrl+W")
.into(),
]),
))])
}
fn menu_handler(event: WindowMenuEvent) {
println!("Menu Item {} clicked", event.menu_item_id())
}
fn main() {
tauri::Builder::default()
.menu(app_menu())
.on_menu_event(menu_handler)
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
When I run this code on Windows 10, the menu accelerator I configured above doesn't work.
When I press "Ctrl+N",nothing happens. (menu_handler function was not called.)
But when I click New menu item, menu_handler works normally.
My cargo.toml:
[package]
name = "tauri-app"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.3", features = [] }
[dependencies]
tauri = { version = "1.3", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
Describe the bug
I created a Tauri App using
yarn create tauri-app
, and then changed themain.rs
file to:When I run this code on Windows 10, the menu accelerator I configured above doesn't work. When I press "Ctrl+N",nothing happens. (
menu_handler
function was not called.) But when I clickNew
menu item,menu_handler
works normally.My
cargo.toml
:Reproduction
No response
Expected behavior
No response
Platform and versions
Stack trace
No response
Additional context
No response