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

[bug] When tray menu is replaced while it's opened an old menu stays on the screen #129

Closed
vovayatsyuk opened this issue Oct 4, 2023 · 5 comments

Comments

@vovayatsyuk
Copy link

Describe the bug

I'm creating this issue in addition to our recent talk on Twitter: https://twitter.com/TauriApps/status/1709573174269002065.

If the tray menu is opened during its change (tray_handle().set_menu()), an old menu stays visible. Users have to reopen the menu to see the changes.

Here is the video of the sample repo:

Area.mp4

Reproduction

I've made a repo: https://github.com/vovayatsyuk/tauri-dynamic-tray-menu

Here is the code I use:

use tauri::{CustomMenuItem, SystemTray, SystemTrayMenu};

fn main() {
    let tray_menu = SystemTrayMenu::new();
    let system_tray = SystemTray::new().with_menu(tray_menu);

    tauri::Builder::default()
        .setup(|app| {
            let handle = app.handle();

            std::thread::spawn(move || {
                let mut i = 0;
                loop {
                    std::thread::sleep(std::time::Duration::from_millis(1000));

                    i += 1;
                    let tray_menu = SystemTrayMenu::new().add_item(
                        CustomMenuItem::new("item".to_string(), format!("Item {}", i))
                    );

                    handle.tray_handle().set_menu(tray_menu).unwrap();
                }
            });

            Ok(())
        })
        .system_tray(system_tray)
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Expected behavior

I expect that the old tray menu will be closed and a new one will be opened in its place.

Platform and versions

[✔] Environment
    - OS: Mac OS 14.0.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.72.1 (d5c2e9c34 2023-09-13)
    ✔ Cargo: 1.72.1 (103a7ff2e 2023-08-15)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-apple-darwin (default)
    - node: 20.4.0
    - yarn: 1.22.19
    - npm: 9.7.2

[-] Packages
    - tauri [RUST]: 1.5.1
    - tauri-build [RUST]: 1.5.0
    - wry [RUST]: 0.24.4
    - tao [RUST]: 0.16.4
    - tauri-cli [RUST]: not installed!
    - @tauri-apps/api [NPM]: not installed!
    - @tauri-apps/cli [NPM]: 1.5.1

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../src
    - devPath: ../src

Stack trace

No response

Additional context

No response

@amrbashir
Copy link
Member

I really don't know what the best behavior would be here, it feels weird to replace the menu while it is open, because we would need to close the active menu and then show another menu which is not a good UX for the user IMO.

Also do you have an idea how it works in other frameworks like electron?

@vovayatsyuk
Copy link
Author

vovayatsyuk commented Oct 5, 2023

I agree this is a weird from UX perspective. It would be much nicer to have the ability to add/remove specific items instead of rebuilding whole menu.

Electron closes the old menu and reopens the new one. This is what it looks like on Ubuntu (you should notice flickering caused by closing animation):

Screencast.from.05.10.23.10_48_47.mp4

@amrbashir
Copy link
Member

I agree this is a weird from UX perspective. It would be much nicer to have the ability to add/remove specific items instead of rebuilding whole menu.

Yeah, this is available in tauri 2.0-alpha, and there are no plans to backport it to v1.

Electron closes the old menu and reopens the new one. This is what it looks like on Ubuntu (you should notice flickering caused by closing animation):

Even though this looks like a bad UX, I think we still need to comply

@amrbashir
Copy link
Member

I will move this over to muda so it can be fixed in for v2

@amrbashir amrbashir transferred this issue from tauri-apps/tauri Oct 5, 2023
@vovayatsyuk
Copy link
Author

vovayatsyuk commented Nov 27, 2023

I've just discovered that Ubuntu updates the tray menu automatically. Here is what my sample repo looks like on ubuntu (It doesn't flicker like an electron app):

Screencast.from.27.11.23.13_26_38.mp4

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

No branches or pull requests

2 participants