Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I add some items for Submenu while the program is running? #176

Closed
LeeeSe opened this issue Jul 11, 2024 · 1 comment
Closed

Can I add some items for Submenu while the program is running? #176

LeeeSe opened this issue Jul 11, 2024 · 1 comment
Labels
question Further information is requested

Comments

@LeeeSe
Copy link

LeeeSe commented Jul 11, 2024

I cannot determine which items should be included in the Submenu during program initialization. It depends on the state of the computer at that time. After consulting the documentation, I found that currently, I can only add or remove an entire menu item.

Is there a way to add some items to the Submenu during the program’s runtime?

@FabianLars FabianLars added the question Further information is requested label Jul 11, 2024
@amrbashir
Copy link
Member

you can add/remove items from a submenu without a problem, for example:

let tray_menu = Menu::new(); // or Submenu::new();

let tray_icon = TrayIconBuilder::new()
    .with_menu(Box::new(tray_menu.clone()))
    .with_tooltip("system-tray - tray icon library!")
    .with_icon(icon)
    .build()
    .unwrap();

then later on in your program you can do

tray_menu.append();
tray_menu.remove();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants