The defined menu can be set to all windows using the `menu` API on the `tauri::Builder` struct:
```rust
use tauri::{CustomMenuItem, Menu, MenuItem, Submenu};
fn main() {
let menu = Menu::new(); // configure the menu
tauri::Builder::default()
.menu(menu)
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
### Adding the menu to a specific window
You can create a window and set the menu to be used. This allows defining a specific menu set for each application window.
```rust
use tauri::{CustomMenuItem, Menu, MenuItem, Submenu};
use tauri::WindowBuilder;
fn main() {
let menu = Menu::new(); // configure the menu
tauri::Builder::default()
.create_window(
"main-window".to_string(),
tauri::WindowUrl::App("index.html".into()),
move |window_builder, webview_attributes| {
(window_builder.menu(menu), webview_attributes)
},
)
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
### Listening to events on custom menu items
Each `CustomMenuItem` triggers an event when clicked. Use the `on_menu_event` API to handle them, either on the global `tauri::Builder` or on an specific window.