-
Hi, I have a question open on stackoverflow regarding disabling (some) tray menu items at app start up. Basically, when I try to access the tray items in .setup I'm told the tray is not configured:
That makes sense, but then where can I set the state of the items? I did try to set state when creating the menu items themselves before adding them to the tray menu, but there doesn't seem to be a method to do that. My codes looks like this: let opt1 = CustomMenuItem::new("opt1".to_string(), "Option 1");
let opt2 = CustomMenuItem::new("opt2".to_string(), "Option 2");
let tray_menu = SystemTrayMenu::new()
.add_item(opt1)
.add_item(opt2);
tauri::Builder::default()
.system_tray(SystemTray::new().with_menu(tray_menu))
.setup(|app| {
...
let tray_handle = app.handle().tray_handle();
tray_handle.get_item(&"opt1".to_string()).set_enabled(false);
...
})
.run(tauri::generate_context!())
.expect("error while running tauri application"); TIA |
Beta Was this translation helpful? Give feedback.
Answered by
woubuc
Jul 22, 2021
Replies: 1 comment 1 reply
-
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
amrbashir
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
.disabled()
on yourCustomMenuItem
to set it to disabled right away, before you add it to the menu.From my code:
This results in a disabled menu item that says "Loading...":