#Checkmark before tray menu-item possible?

21 messages · Page 1 of 1 (latest)

random prism
#

there should be a set_selected api

trail hearth
#

cool have to digg the docs for that its still a bit puzzle figuring out how to connect the dots

trail hearth
trail hearth
random prism
#

but cannot get the tray_handle there tried several things you have a suggestion as to how to get access to it there?
Any specific errors or something? The code you posted itself looks alright

#

well, yes. that's exactly why i mentioned that specific example from the docs, you really only have to change the ID and set_title to set_selected. And you could hard code the selected state for now, just to get the code flow running. with hard coding i mean, have your menu be not selected by default and always call item_handle.set_selected(true) - of course that only works once per application lifetime but it's enough to get that part up and running.

trail hearth
trail hearth
#

so i still did not got this implemented since i define my code based on the pomodoro example and there there is no tray object available on the position where i should do the triggers it seems.

trail hearth
#

I fixed ( with your great helps) most or all of my issues so far with Tauri only this one is still somehow very hard.

#

I can't recall exactly since i restored to original since i broke it, but it seems i had no way of setting the checkmark in the tray because I was missing the app_handle there. I had to modify the setup_tray method and others to pass it and there it broke

random prism
#

in setup_tray you can get an AppHandle via app.handle()

#

similar to how they use app.get_window

trail hearth
#

i try it once again today i tried it a few times got a looott of errors then

#

then it gets the main_window with ``` let main_window = app.get_window(MAIN_WINDOW_LABEL).unwrap();

#

basically below the file it does this system_tray .on_event(create_window_event_handler(app.handle())) .build(app) to be precise and then in that on_event method It passes the app.handle

#

Then it loads the even method ```fn create_window_event_handler<R: Runtime>(app_handle: AppHandle<R>) -> impl Fn(SystemTrayEvent) {
let main_window = app_handle.get_window(MAIN_WINDOW_LABEL).unwrap();
// let tray_handle = app_handle.tray_handle().unwrap(); // Get the tray_handle

move |event| match event {
SystemTrayEvent::LeftClick { position, size, .. } => {
if main_window.is_visible().unwrap() {
...
main_window.set_position(window_position).unwrap();
main_window.show().unwrap();
main_window.set_focus().unwrap();
}
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {

  MENU_TEST_ID => {
    so here i would set the checkmarked menu item right?
  }
#

that would be the right spot right? i refactored all code for better readability