diff --git a/.changes/menu-export.md b/.changes/menu-export.md new file mode 100644 index 00000000000..0b7b1dc07ca --- /dev/null +++ b/.changes/menu-export.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Export `MenuHandle` and `MenuEvent` types on `tauri::window`. diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 41258bbbed5..79992e4f20a 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -6,6 +6,10 @@ #[cfg_attr(doc_cfg, doc(cfg(feature = "menu")))] pub(crate) mod menu; +#[cfg(feature = "menu")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "menu")))] +pub use menu::{MenuEvent, MenuHandle}; + use crate::{ api::config::WindowUrl, app::AppHandle, @@ -307,13 +311,10 @@ impl Window

{ /// Registers a menu event listener. #[cfg(feature = "menu")] #[cfg_attr(doc_cfg, doc(cfg(feature = "menu")))] - pub fn on_menu_event) + Send + 'static>( - &self, - f: F, - ) -> uuid::Uuid { + pub fn on_menu_event) + Send + 'static>(&self, f: F) -> uuid::Uuid { let menu_ids = self.manager.menu_ids(); self.window.dispatcher.on_menu_event(move |event| { - f(menu::MenuEvent { + f(MenuEvent { menu_item_id: menu_ids.get(&event.menu_item_id).unwrap().clone(), }) }) @@ -323,8 +324,8 @@ impl Window

{ /// Gets a handle to the window menu. #[cfg(feature = "menu")] - pub fn menu_handle(&self) -> menu::MenuHandle

{ - menu::MenuHandle { + pub fn menu_handle(&self) -> MenuHandle

{ + MenuHandle { ids: self.manager.menu_ids(), dispatcher: self.dispatcher(), } diff --git a/core/tauri/src/window/menu.rs b/core/tauri/src/window/menu.rs index b6468d80e7e..d01c84468c6 100644 --- a/core/tauri/src/window/menu.rs +++ b/core/tauri/src/window/menu.rs @@ -59,6 +59,7 @@ impl Clone for MenuItemHandle

{ } impl MenuHandle

{ + /// Gets a handle to the menu item that has the specified `id`. pub fn get_item(&self, id: &P::MenuId) -> MenuItemHandle

{ for (raw, item_id) in self.ids.iter() { if item_id == id {