Skip to content

Commit

Permalink
fix(tray): submenus not working
Browse files Browse the repository at this point in the history
Fixes a regression from previous tray fixes that caused submenus within
the main tray menu to never show.

Fixes #455
  • Loading branch information
JakeStanger committed Feb 25, 2024
1 parent 0675b91 commit c62d475
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/modules/tray/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,23 @@ enum TrayMenuWidget {

impl TrayMenuItem {
fn new(info: &MenuItemInfo, tx: mpsc::Sender<i32>) -> Self {
let mut submenu = HashMap::new();
let menu = Menu::new();

macro_rules! add_submenu {
($menu:expr, $widget:expr) => {
if !info.submenu.is_empty() {
for sub_item in &info.submenu {
let sub_item = TrayMenuItem::new(sub_item, tx.clone());
call!($menu, add, sub_item.widget);
submenu.insert(sub_item.id, sub_item);
}

$widget.set_submenu(Some(&menu));
}
};
}

let widget = match (info.menu_type, info.toggle_type) {
(MenuType::Separator, _) => TrayMenuWidget::Separator(SeparatorMenuItem::new()),
(MenuType::Standard, ToggleType::Checkmark) => {
Expand All @@ -200,6 +215,8 @@ impl TrayMenuItem {
.active(info.toggle_state == ToggleState::On)
.build();

add_submenu!(menu, widget);

{
let tx = tx.clone();
let id = info.id;
Expand All @@ -212,12 +229,13 @@ impl TrayMenuItem {
TrayMenuWidget::Checkbox(widget)
}
(MenuType::Standard, _) => {
let builder = MenuItem::builder()
let widget = MenuItem::builder()
.label(&info.label)
.visible(info.visible)
.sensitive(info.enabled);
.sensitive(info.enabled)
.build();

let widget = builder.build();
add_submenu!(menu, widget);

{
let tx = tx.clone();
Expand All @@ -236,7 +254,7 @@ impl TrayMenuItem {
id: info.id,
widget,
menu_widget: menu,
submenu: HashMap::new(),
submenu,
tx,
}
}
Expand Down

0 comments on commit c62d475

Please sign in to comment.