Skip to content

Commit

Permalink
refactor(menu,tray): add wrappers (#7622)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Aug 16, 2023
1 parent 5c95152 commit af3268a
Show file tree
Hide file tree
Showing 7 changed files with 494 additions and 16 deletions.
8 changes: 4 additions & 4 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,16 +1461,16 @@ impl<R: Runtime> Builder<R> {
{
// setup menu event handler
let proxy = runtime.create_proxy();
crate::menu::MenuEvent::set_event_handler(Some(move |e| {
let _ = proxy.send_event(EventLoopMessage::MenuEvent(e));
muda::MenuEvent::set_event_handler(Some(move |e: muda::MenuEvent| {
let _ = proxy.send_event(EventLoopMessage::MenuEvent(e.into()));
}));

// setup tray event handler
#[cfg(feature = "tray-icon")]
{
let proxy = runtime.create_proxy();
crate::tray::TrayIconEvent::set_event_handler(Some(move |e| {
let _ = proxy.send_event(EventLoopMessage::TrayIconEvent(e));
tray_icon::TrayIconEvent::set_event_handler(Some(move |e: tray_icon::TrayIconEvent| {
let _ = proxy.send_event(EventLoopMessage::TrayIconEvent(e.into()));
}));
}
}
Expand Down
7 changes: 4 additions & 3 deletions core/tauri/src/menu/builders/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use muda::{MenuId, NativeIcon};

use crate::{menu::IconMenuItem, Icon, Manager, Runtime};
use crate::{
menu::{IconMenuItem, MenuId, NativeIcon},
Icon, Manager, Runtime,
};

/// A builder type for [`IconMenuItem`]
pub struct IconMenuItemBuilder {
Expand Down
8 changes: 5 additions & 3 deletions core/tauri/src/menu/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<R: Runtime> IconMenuItem<R> {
let item = muda::IconMenuItem::with_native_icon(
text,
enabled,
native_icon,
native_icon.map(Into::into),
acccelerator.and_then(|s| s.as_ref().parse().ok()),
);
Self {
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<R: Runtime> IconMenuItem<R> {
id,
text,
enabled,
native_icon,
native_icon.map(Into::into),
acccelerator.and_then(|s| s.as_ref().parse().ok()),
);
Self {
Expand Down Expand Up @@ -207,7 +207,9 @@ impl<R: Runtime> IconMenuItem<R> {
/// - **Windows / Linux**: Unsupported.
pub fn set_native_icon(&mut self, _icon: Option<NativeIcon>) -> crate::Result<()> {
#[cfg(target_os = "macos")]
return run_main_thread!(self, |mut self_: Self| self_.inner.set_native_icon(_icon));
return run_main_thread!(self, |mut self_: Self| self_
.inner
.set_native_icon(_icon.map(Into::into)));
#[allow(unreachable_code)]
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions core/tauri/src/menu/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// SPDX-License-Identifier: MIT

use super::sealed::ContextMenuBase;
use super::{IsMenuItem, MenuItemKind, PredefinedMenuItem, Submenu};
use super::{AboutMetadata, IsMenuItem, MenuItemKind, PredefinedMenuItem, Submenu};
use crate::Window;
use crate::{run_main_thread, AppHandle, Manager, Position, Runtime};
use muda::ContextMenu;
use muda::{AboutMetadata, MenuId};
use muda::MenuId;

/// Expected submenu id of the Window menu for macOS.
pub const WINDOW_SUBMENU_ID: &str = "__tauri_window_menu__";
Expand Down
Loading

0 comments on commit af3268a

Please sign in to comment.