#Checkmark before tray menu-item possible?
21 messages · Page 1 of 1 (latest)
you can handle click events similar to this https://tauri.app/v1/guides/features/system-tray#updating-context-menu-items but of course instead of set_title you'd use set_selected.
and to save the value you'd use tauri::Statem example: https://docs.rs/tauri/latest/tauri/trait.Manager.html#examples-5
cool have to digg the docs for that its still a bit puzzle figuring out how to connect the dots
so i 1. set a click handler on the menu item i want to apply the checkmark to. 2. on click triggered i do a .set_selected on the menu item to set it selected.
can i use the native os kc for storing data also, is there some "wrapper" for that perhaps?
sounds like complete overkill to use the keychain (i assume this is what you meant by kc) for this irrelevant data and not just for secrets but yes, there are rust crates for that.
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.
Ah yes good point i proceed to that. The eventhandler had problems to get the tray handle not behind desk i post error lateron. I run it true gpt sometimes giving it tauri src and it points out most of times my simple mistakes
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.
I fixed ( with your great helps) most or all of my issues so far with Tauri only this one is still somehow very hard.
Could you give me some final guidance on this? I tried it 3 times to implement probably its very simple but im using the code here as foundation: https://github.com/G07cha/pomodoro/blob/master/src-tauri/src/ui/tray.rs
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
in setup_tray you can get an AppHandle via app.handle()
similar to how they use app.get_window
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