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] After context menus are opened, menu events are no longer received for other menus. #162

Closed
gulbanana opened this issue Mar 8, 2024 · 5 comments · Fixed by #166 or #171
Closed

Comments

@gulbanana
Copy link

Describe the bug

My application has multiple context menus. Once I've popped them each up a couple of times, the handler I've set with on_menu_event() only receives events for the most recent kind of context menu - not others, and not the main menubar.

Reproduction

https://github.com/gulbanana/repro-tauri-contextmenus
To demonstrate the problem:

  • npm install
  • npm run tauri dev
  • Click on the two buttons repeatedly, selecting an item from the menu each time.
  • Observe that at first, the text on the screen updates when you select menu items; after a couple of clicks, it stops updating.

Expected behavior

I expect that menu events for existing menus continue to be delivered after using a context menu.

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.19045 X64
    ✔ WebView2: 122.0.2365.66
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.11.0
    - pnpm: 8.15.4
    - yarn: 1.22.21
    - npm: 8.5.2

[-] Packages
    - tauri [RUST]: 2.0.0-beta.10
    - tauri-build [RUST]: 2.0.0-beta.8
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.4
    - @tauri-apps/cli [NPM]: 2.0.0-beta.8

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

Stack trace

No response

Additional context

No response

@gulbanana
Copy link
Author

Here's a brief recording of the bug in action. After menu2 is activated, menu1 no longer functions.

repro-tauri-contextmenus_RgX9HE2SAV.mp4

@gulbanana
Copy link
Author

I debugged this a bit and found that muda's platform_impl::windows::menu_subclass_proc is receiving a dwrefdata for the last opened context menu only. I believe this is because all the calls to SetWindowSubclass() in mod.rs use the same HWND - whichever one is most recent will overwrite the refdata.

@gulbanana
Copy link
Author

Here's a PR with a hack that seems to work around the issue. Not the right way to fix it long-term, but hopefully having a demo helps.
#159

@amrbashir amrbashir transferred this issue from tauri-apps/tauri Mar 11, 2024
amrbashir added a commit that referenced this issue Mar 11, 2024
@gulbanana
Copy link
Author

Unfortunately, the fix didn't work. I've updated the original repro (same link) to use tauri beta 12 and muda 0.12.1; the problem still occurs.

I believe this is because, while muda now uses a separate subclass for the context window's event handler, it still shares that subclass between all context menus. So only the last-opened context menu can ever receive events.

@FabianLars FabianLars reopened this Mar 19, 2024
amrbashir added a commit that referenced this issue Mar 26, 2024
Overriding the subclass using the same ID and function pointer, results in only updating the reference data
https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-setwindowsubclass#remarks

closes #162
@gulbanana
Copy link
Author

Thanks for the fix, I'll try the new version soon!

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