-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix TrayIcon menu crash #16024
Fix TrayIcon menu crash #16024
Conversation
You can test this PR using the following package version. |
|
@cla-avalonia agree |
bb3f939
to
c71d999
Compare
(rebase) |
You can test this PR using the following package version. |
samples/TrayIcon/AboutWindow.axaml
Outdated
@@ -0,0 +1,18 @@ | |||
<Window xmlns="https://github.com/avaloniaui" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about adding yet another project here.
Ideally, TrayIcon test should be added to the IntegrationTestApp project + new e2e tests written per each platform (can be done separately).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, okay. Coming at this from the other direction, when I first started writing my application, I found all existing documentation of TrayIcon
to be incomplete and there were no samples. This would be the first sample showing how to use TrayIcon
as far as I am aware. It serves to illustrate the crash in this PR, but after the PR is merged, it serves as a TrayIcon
example for new developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a coded UI test infrastructure in place that would allow automated testing of this? If so then it's also a good point to add a test of this crash to that as well. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I duplicated the TrayIcon
stuff into IntegrationTestApp
but no menu appears when I click on the tray icon. I tried a bunch of different ways to make IntegrationTestApp
be more like TrayIcon
but I wasn't able to figure out what the difference is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see project Avalonia.IntegrationTests.Appium
. Does Appium support interacting with tray icons? I tried some searches related to this and couldn't find anything conclusive. I've never worked with Appium before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, well, I tried to merge it in there, but when I run the IntegrationTestApp
project, the menu doesn't show up when clicking on the tray icon. Not sure how it's different from the TrayIcon
sample, but there must be something...
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/icon.ico">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="Show _Test Window" Command="{Binding ShowWindowCommand}" />
</NativeMenu>
</TrayIcon.Menu>
</TrayIcon>
</TrayIcons>
</TrayIcon.Icons>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very strange. It continues to not work for me. I tried removing the command binding just in case that was why but it didn't fix it. Since I can't get the menu to show up, I can't confirm the crash with IntegrationTestApp
. It's a technicality but I would feel better if you could confirm the crash without c71d999 and the fix with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, rather, with and without 04e3225. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I switched from GNOME Desktop to KDE Plasma and now the menu shows up, and I can confirm the fix. :-) Definitely crashes without 04e3225, definitely fixed with, at least on my end.
c71d999
to
04e3225
Compare
You can test this PR using the following package version. |
04e3225
to
ad86f32
Compare
You can test this PR using the following package version. |
6430a46
to
4ce9ad7
Compare
(Restored the command binding, because it does in fact work. :-) ) |
You can test this PR using the following package version. |
Updated App.axaml.cs to set the DataContext for binding and provide a command implementation. Added a project reference to Avalonia.ReactiveUI.
…ead if it ends up running on a non-UI thread.
4ce9ad7
to
5afd3b9
Compare
You can test this PR using the following package version. |
You can test this PR using the following package version. |
* Updated the TrayIcon in IntegrationTestApp to have an associated menu. Updated App.axaml.cs to set the DataContext for binding and provide a command implementation. Added a project reference to Avalonia.ReactiveUI. * Updated CanExecuteChanged in NativeMenuItem.cs to thunk to the UI thread if it ends up running on a non-UI thread. * Replace ReactiveUI with MiniMvvm to simplify integration tests app --------- Co-authored-by: Max Katz <[email protected]>
* Updated the TrayIcon in IntegrationTestApp to have an associated menu. Updated App.axaml.cs to set the DataContext for binding and provide a command implementation. Added a project reference to Avalonia.ReactiveUI. * Updated CanExecuteChanged in NativeMenuItem.cs to thunk to the UI thread if it ends up running on a non-UI thread. * Replace ReactiveUI with MiniMvvm to simplify integration tests app --------- Co-authored-by: Max Katz <[email protected]>
This PR addresses a crash that occurs when activating TrayIcon menu items. It contains two commits:
samples
project calledTrayIcon
which should work. It follows all the guidelines, but with the current Avalonia code it crashes as soon as any tray icon menu item is activated.TrayIcon
sample by thunking to the UI thread when processing aNativeMenuItem.CanExecuteChanged
notification.What is the current behavior?
At least on Ubuntu 24.04 running Xorg, activating a tray icon menu item causes the process to crash immediately with the exception:
This is described in detail in #15940.
What is the updated/expected behavior with this PR?
With the fix to
NativeMenuItem.cs
, tray icon menu items can now be activated without the process crashing.How was the solution implemented (if it's not obvious)?
Dispatcher.UIThread.Invoke
Checklist
Fixed issues
Fixes #15940