Skip to content

Commit

Permalink
fix(core): export MenuHandle and MenuEvent (#2148)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jul 4, 2021
1 parent 2e2dc7c commit acb8892
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/menu-export.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Export `MenuHandle` and `MenuEvent` types on `tauri::window`.
15 changes: 8 additions & 7 deletions core/tauri/src/window.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -307,13 +311,10 @@ impl<P: Params> Window<P> {
/// Registers a menu event listener.
#[cfg(feature = "menu")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "menu")))]
pub fn on_menu_event<F: Fn(menu::MenuEvent<P::MenuId>) + Send + 'static>(
&self,
f: F,
) -> uuid::Uuid {
pub fn on_menu_event<F: Fn(MenuEvent<P::MenuId>) + 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(),
})
})
Expand All @@ -323,8 +324,8 @@ impl<P: Params> Window<P> {

/// Gets a handle to the window menu.
#[cfg(feature = "menu")]
pub fn menu_handle(&self) -> menu::MenuHandle<P> {
menu::MenuHandle {
pub fn menu_handle(&self) -> MenuHandle<P> {
MenuHandle {
ids: self.manager.menu_ids(),
dispatcher: self.dispatcher(),
}
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/window/menu.rs
Expand Up @@ -59,6 +59,7 @@ impl<P: Params> Clone for MenuItemHandle<P> {
}

impl<P: Params> MenuHandle<P> {
/// Gets a handle to the menu item that has the specified `id`.
pub fn get_item(&self, id: &P::MenuId) -> MenuItemHandle<P> {
for (raw, item_id) in self.ids.iter() {
if item_id == id {
Expand Down

0 comments on commit acb8892

Please sign in to comment.